1>A friend asked a question today:
Why is there no error when using the File control to read the paths of pictures, documents, and other files, but when reading video files (such as rmvb, etc.), there is an error that the page cannot be displayed.
The code snippet is as follows:
private void btnUpFiles_Click(object sender, System.EventArgs e)
{
string pathName=this.File1.PostedFile.FileName.ToString();
Response.Write(pathName);
}
2>Start solving the problem:
I thought it was a problem with getting the path string, so I intercepted the path and file name first, then intercepted the file extension, and saved them as strings, but there was always an error. The code snippet is as follows:
string fullname=this.File1.PostedFile.FileName.ToString();//Get the full path
string firstname=fullname.Substring(0,fullname.LastIndexOf(".")+1);//Get the path and file name, and remove the file suffix
Session["firstname"]=firstname;//Save in a session
char [] spliter={'.'};//The delimiter used to split the string
string [] fileName=this.File1.PostedFile.FileName.Split(spliter);//Save each part of the full path split in the array
Session["lastname"]=fileName[fileName.Length-1];// Save the last element (name suffix) in the array as a session
Response.Redirect("test.aspx");//I want to pass it to this page for testing.
The above method still fails, and the cause of the error seems to have nothing to do with strings at all.
3>Netizen "@@" suggested that it was an httpRuntime problem (thank you):
Solution to the problem: Add the following code to <system.web></system.web> in web.config:
<httpRuntime executionTimeout="600" maxRequestLength="951200"
useFullyQualifiedRedirectUrl="true" minFreeThreads="8"
minLocalRequestFreeThreads="4" appRequestQueueLimit="100" enableVersionHeader="true"/>
4>Explanation from MSDN:
httpRuntime is the configuration asp.net http runtime settings to determine how to handle requests to asp.net applications.
executionTimeout: Indicates the maximum time limit allowed to execute the request, in seconds
maxRequestLength: Indicates the maximum file upload size supported by ASP.NET. This limit can be used to prevent denial of service attacks caused by users passing large numbers of files to the server. The specified size is in KB. The default value is 4096 KB (4 MB).
useFullyQualifiedRedirectUrl: Indicates whether the client redirect is fully qualified (in the " http://server/path " format, which is required for some mobile controls), or whether a relative redirect is sent to the client instead end. If True, all redirects that are not fully qualified will be automatically converted to fully qualified format. false is the default option.
minFreeThreads: Specifies the minimum number of free threads allowed to execute new requests. ASP.NET keeps a specified number of threads free for requests that require additional threads to complete their processing. The default value is 8.
minLocalRequestFreeThreads: Indicates the minimum number of free threads maintained by ASP.NET that are allowed to execute new local requests. This number of threads is reserved for incoming requests from the local host in case some requests make subrequests to the local host during their processing. This avoids possible deadlocks caused by recursively re-entering the Web server.
appRequestQueueLimit: Indicates the maximum number of requests that ASP.NET will queue for the application. Requests are queued when there are not enough free threads to handle the request. When the queue exceeds the limit specified in this setting, incoming requests will be rejected with a "503 - Server Too Busy" error message.
enableVersionHeader: Indicates whether ASP.NET should output a version header. Microsoft Visual Studio 2005 uses this property to determine the version of ASP.NET currently in use. For production environments, this property is not required and can be disabled.