关于动态存储临时图像并在Web服务器的文件系统上处理其清理的主题:(使用.NET 3.5中的C#)。global.asax的使用和范围(用于应用程序结束后的文件清理)
有人建议我使用global.asax
文件来处理这个问题。
我只是不明白这个东西是如何工作的。
我有两个单独的应用程序...
我已经想通了,在Global.asax应该是在网站的根目录下。
问题:
1)如何我得到的global.asax
火的只有这两个特定的应用程序。
2)两个应用程序都需要创建一个字符串列表(文件位置),然后在应用程序终止时删除它们。我是否在应用程序中实例化这个数组,或者在global.asax
?
我的代码看起来就像这样:
List<string> fileLocations = new List<string>();
//I don't know where to put this.
//The next line of code will be in both applications (this could
//be called many times in one application session. The names of
//the files are generated from the clock (milliseconds and
//seconds combined, I might change this to use the actual
//random class combined with sessionID)
fileLocations.Add(file);
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
foreach(string file in fileLocations)
{
if(File.Exists(file))
File.Delete(file);
}
}
我感到困惑在Global.asax实际上是如何工作的。它是否像界面一样使用?
因此,没有简单的方法来检测某人完成使用应用程序并运行清理脚本的时间?我觉得这应该比它容易得多:/ – Dave 2009-08-06 19:34:31
那么,如果用户登录,那么你也可以在Global.asax中使用Session_End事件。默认情况下,它是20分钟,但你可以设置自己的限制。请参阅http://stackoverflow.com/questions/621744/how-to-handle-session-end-in-global-asax和http://justgeeks.blogspot.com/2008/07/aspnet-session-timeouts.html – 2009-08-06 20:06:06
啊,好的。 那么如果我在global.asax文件中声明一个List,它会为每个用户的会话实例化一个新的列表,还是我在我的程序中声明这个列表,并以某种方式global.asax访问它。 就像我说的,我对基本的问题表示歉意......我通常很擅长于自己计算这些东西,但出于某种原因,global.asax对我来说并不是很直观。 – Dave 2009-08-06 20:15:29