Problem:
Today, you encounter a problem, upload an Excel file with the FileUpload control, invoke the "Fileupload1.saveas" method with a button control, and a server 500 error occurs when you click the button. Such as:
Workaround:
In the button event break point, debugging code, found that there is no event, a direct 500 error, should not be a code bug.
Later found that the file 4.28M, is not more than the default limit (the default maximum seems to be 4M)? The
Summary :
It is not difficult to understand carefully. When you click the button and the page is posted back to the server, the ASP. NET internal mechanism should be to upload the file directly to the server. Although the fileupload of the SaveAs method is to upload the file, but in fact, as long as the postback page file has been uploaded. Otherwise, there is no chance of uploading in this life cycle.
The reason for reporting a 500 error directly is the error reported by IIS according to the configuration. At this time, there is no back-end code to take over, so that there is no point above the phenomenon of a breakpoint.
It seems that the server control pit is still quite large, there are strange problems, it is necessary to think about its implementation principle, the problem is not difficult to solve.
FileUpload Control causes 500 error