C# ASP.NET:删除文件夹后会话已过期
我正在编写代码,将文件移动到另一个文件夹,并删除ASP.NET应用程序中以前的文件夹和文件。删除文件夹后,我的会话将过期。如何限制会话值过期 非常正确。之所以会发生这种情况,是因为删除操作会更改ASP.NET应用程序的文件夹树,从而强制应用程序回收。请看这里:非常正确。之所以会发生这种情况,是因为删除操作会更改ASP.NET应用程序的文件夹树,从而强制应用程序回收。请参见此处:在Global.asax页面中使用以下代码C# ASP.NET:删除文件夹后会话已过期,c#,asp.net,C#,Asp.net,我正在编写代码,将文件移动到另一个文件夹,并删除ASP.NET应用程序中以前的文件夹和文件。删除文件夹后,我的会话将过期。如何限制会话值过期 非常正确。之所以会发生这种情况,是因为删除操作会更改ASP.NET应用程序的文件夹树,从而强制应用程序回收。请看这里:非常正确。之所以会发生这种情况,是因为删除操作会更改ASP.NET应用程序的文件夹树,从而强制应用程序回收。请参见此处:在Global.asax页面中使用以下代码 void Application_Start(object sender,
void Application_Start(object sender, EventArgs e)
{
System.Reflection.PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
object o = p.GetValue(null, null);
System.Reflection.FieldInfo f = o.GetType().GetField("_dirMonSubdirs", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
System.Reflection.MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { });
}
在Global.asax页面中使用以下代码
void Application_Start(object sender, EventArgs e)
{
System.Reflection.PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
object o = p.GetValue(null, null);
System.Reflection.FieldInfo f = o.GetType().GetField("_dirMonSubdirs", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
System.Reflection.MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { });
}
请在globle.asax中的Session_End方法中编写目录删除代码
void Session_End(object sender, EventArgs e)
{
SampleDelete();
}
private static void SampleDelete()
{
try
{
string samplesss = AppDomain.CurrentDomain.BaseDirectory + "\\temp";
string[] array1 = System.IO.Directory.GetDirectories(samplesss);
try
{
foreach (string item in array1)
{
System.IO.Directory.Delete(item, true);
}
}
catch (Exception ex)
{ }
}
catch (Exception ex)
{
}
}
请在globle.asax中的Session_End方法中编写目录删除代码
void Session_End(object sender, EventArgs e)
{
SampleDelete();
}
private static void SampleDelete()
{
try
{
string samplesss = AppDomain.CurrentDomain.BaseDirectory + "\\temp";
string[] array1 = System.IO.Directory.GetDirectories(samplesss);
try
{
foreach (string item in array1)
{
System.IO.Directory.Delete(item, true);
}
}
catch (Exception ex)
{ }
}
catch (Exception ex)
{
}
}
但是如何避免会话值过期请阅读主题并避免删除ASP.NET应用程序中的文件夹。本主题讨论了不同的选项,应该可以帮助您达成解决方案。但是如何避免会话值过期请阅读本主题并避免删除ASP.NET应用程序中的文件夹。本主题讨论了不同的选项,应该可以帮助您达成解决方案。请不要关闭此问题。可能这需要编辑。那么,您能解决此问题吗?请不要关闭此问题。可能这需要编辑。那么,你能解决这个问题吗?