Wednesday 13 February 2013

Get a list of countries for a dropdown

This is a surprisingly difficult question to answer, as it's not all as simple as just adding the System.Globalization namespace and getting stuck in.

It appears that there are in fact a large amount of incorrect / incomplete answers on the subject.

There is a web service that you could add and call which may prove to be more up-to-date than the .NET framework itself, but the easiest, fastest and WORKING method of adding countries to a drop-down is to use the method mentioned in this StackOverflow question:

It's a life-saver!

Thursday 3 January 2013

You get "Maximum request length exceeded" when you upload big files

I came across this issue in an MVC 3 project I'm working on at the moment, where when the user tried to upload files greater than 4mb in size, they were getting this exception.
If you're using IIS 7, a lot of answers online seem to point to increasing the maxAllowedContentLength attribute for the requestLimits element in the web.config.
Others also say if you're using IIS 6, you need to increase the maxRequestLength attribute for the httpRuntime element, also in the web.config.
I had to do both.
Within <system.web>, add:

And within <system.webServer>, add:
IMPORTANT:

Both of these values must match. In this case, my max upload is 1024 megabytes.

maxRequestLength has 1048576 KILOBYTES, and maxAllowedContentLength has 1073741824 BYTES.

It's quite easy to overlook this difference in requirements for each attribute, and mismatching these values can cause other errors.
I also answered this question on StackOverflow.