2

asp.net アプリでいくつかの一時ファイルを作成します。ユーザーがそれらを使い終わったら、それらを削除する必要があります。

私は試した

 void Session_End(object sender, EventArgs e) 
    {

        System.IO.File.Delete(@"C:\Temp\test.doc");        
    }

しかし、それは機能していません。

何か案は?

4

3 に答える 3

2

このフォルダでiisuserに権限を付与する必要があります

于 2012-11-14T12:03:38.087 に答える
2

There is no good reliable (works 100% of the time) way to determine when a user leaves a web application. While conventional means will work when all is running as expected, there are edge cases that can happen that will orphan data, e.g.

The user's computer freezes or crashes... The server freezes or crashes... The user's internet connection fails... The server's internet connection fails...

You get the idea. For this reason, I personally prefer to do all processing in memory instead of writing temporary files to the web server's hdd. That way the .Net garbage collector will handle cleaning up any orphaned data.

If, however, you are processing data in sufficiently large quantities to make keeping it in memory not a viable option, set up a Windows Service or scheduled task to perform cleanup once enough time has passed to ensure that the files are stale. Continue to attempt cleanup at runtime, but the alternate method should allow you to handle any data which becomes orphaned over time.

于 2012-11-14T13:11:46.210 に答える