We are at ASP. . NET web hosting websites use multithreading technology. But there is a problem:
The main web page thread has the read and write permissions on the file, but the new thread does not have the permission.
For exampleCode: Create a file in the main thread and the new thread respectively. The execution result is that the file is successfully created by the main thread, and the sub-thread has an operation error: no permission to create the file. What is going on here? How can we avoid this situation? Thank you.
Code
We are at ASP. . NET web hosting websites use multithreading technology. But there is a problem:
The main web page thread has the read and write permissions on the file, but the new thread does not have the permission.
For example, use the following code: create a file in the main thread and the new thread respectively. The execution result is that the file is successfully created by the main thread, and the sub-thread has an operation error: no permission to create the file. What is going on here? How can we avoid this situation? Thank you.
< Script runat = " Server " >
Protected Void Page_load ( Object Sender, eventargs E)
{
System. Io. file. writealltext (server. mappath ( " /114/B " + Datetime. Now. millisecond. tostring
()),"Dd");
Response. Write (application ["E"]);
System. Threading. thread t= NewSystem. Threading. Thread (NewSystem. Threading. threadstart
(Dd ));
T. Start ();
Response. End ();
}
Private Void Dd ()
{
Try
{
System. Io. file. writealltext (server. mappath ( " /114/ " +
Datetime. Now. millisecond. tostring ()), " Dd " );
}
Catch (Exception E)
{
Application [ " E " ] = E. Message + E. helplink + E. Source + E. stacktrace + E. targetsite;
}
}
</Script>