问题
I have implemented a small method
for my site where I upload an image. using a FileUpload control, I choose an image, and then when I hit a button, the UploadImage()
method is generated.
The UploadImage()
method stores the image in a folder in the server and stores its path in the Database. It also checks the file size of the image, if greater than a megabyte, an alert is displayed, else, the image is upload and stored. This has been tested with a few images ranging from 45KB to 900KB. It has worked perfectly.
THE PROBLEM:
When tested with a few images of approximately 4MB, sometimes it shows the 'error' since it is greater than 1MB, but at other times (I do not know why), Google Chrome directs me to a page telling me that the localhost has been interrupted.
When debugging, I do not even enter the button Upload click method! I find this very strange. The extension of the image doesn't seem to be the problem since I am testing with .jpg and .png.
Did some one experience the same problem? Is there a guru that can help me?
Thank you very much.
update:
it seems that files of 4052kb have worked correctly (i.e. an error message was displayed) but files over 4098kb) resulted in a local host interrupt. When the button is clicked, the browser below shows 'sending request' and uploading (0%) and displays "The connection to localhost was interrupted."
回答1:
Please take a look at the maxRequestLength
of the httpRuntime
element of the web.config
.
http://msdn.microsoft.com/en-us/library/e1f13641.aspx
This is where you set the maximum request length. When it is exceeded, the runtime throws an exception. The default size is 4096KB.
来源:https://stackoverflow.com/questions/8114571/image-upload-local-host-interrupt