gpt4 book ai didi

asp.net - IIS 7.0删除子目录时如何防止AppDomain回收?

转载 作者:行者123 更新时间:2023-12-02 10:08:15 25 4
gpt4 key购买 nike

我有一个 ASP.Net Web 应用程序,允许用户将文件上传到与 Web 应用程序位于同一虚拟目录中的 uploads 目录。每个上传的文件都会进入一个以用户 session ID 命名的临时子目录。完成文件后,我删除临时子目录。唯一的问题是,当删除子目录时,AppDomain 会被回收并终止所有用户 session (使用inproc session 状态)。罪魁祸首似乎是一个FileChangesMonitor,它监视应用程序中所有子目录的更改。

以下代码在 Windows Server 2003 上运行的 IIS 6.0 中运行良好,可禁用子目录的 FileChangesMonitor,但由于某种原因,它在 Windows Server 2008 上的 IIS 7.0 中不起作用:

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[] { });

我找到了另一个完全禁用 FileChangesMonitor 的解决方案 here 。但这不是理想的解决方案,因为我仍然想监视除 uploads 目录中的临时子目录之外的所有其他文件。

为什么这在 IIS 6.0 中有效,而在 IIS 7.0 中无效?

在 IIS 7.0 中,您可以在要禁用回收的虚拟文件夹中指定子目录吗?

是否有另一种不使用反射的方法来做到这一点?

最佳答案

@fyjham 是对的,您需要将上传文件夹移至 webroot 之外。如果这是一个面向公众的网站,那么将其置于 webroott 下首先就会存在安全风险。

关于asp.net - IIS 7.0删除子目录时如何防止AppDomain回收?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2098436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com