为了账号安全,请及时绑定邮箱和手机立即绑定

修改web.config时,如何防止ASP.NET应用程序重新启动?

修改web.config时,如何防止ASP.NET应用程序重新启动?

慕码人2483693 2019-11-14 15:23:56
我通过该ApplicationHost.CreateApplicationHost方法托管ASP.NET运行时。当我web.config在应用程序运行时进行修改时,我发现ThreadAbortException抛出了很多第一次机会。这是在我的应用程序崩溃之前的正确时间。我认为这是因为运行时已检测到配置更改,并希望重新启动。对于我们来说,这实际上不是受支持的方案,因此,我希望可以关闭自动重装功能。有谁知道如何做到这一点?
查看完整描述

3 回答

?
DIEA

TA贡献1820条经验 获得超2个赞

同样,我遇到了一个更大的问题- 对AppDomain基本目录中的任何文件或子文件夹进行更改都会导致托管环境关闭。对于我们的应用程序来说,这是一个很大的问题,因为我们在同一AppDomain中运行WPF UI,并且在不干扰用户的情况下无法重新启动它。


我真的想避免为应用程序的基于Web的部分运行单独的AppDomain,所以我做了Reflector的挖掘工作。我发现罪魁祸首是内部阶级FileChangesMonitor。


所以我写了一个可怕的可怕的反思黑客来解决这个问题。我以为我会将其发布在这里,作为其他有相同问题的潜在解决方案。您只需要致电HttpInternals.StopFileMonitoring()即可在文件/文件夹更改禁用关闭功能。


internal static class HttpInternals

{

    private static readonly FieldInfo s_TheRuntime = typeof(HttpRuntime).GetField("_theRuntime", BindingFlags.NonPublic | BindingFlags.Static);


    private static readonly FieldInfo s_FileChangesMonitor = typeof(HttpRuntime).GetField("_fcm", BindingFlags.NonPublic | BindingFlags.Instance);

    private static readonly MethodInfo s_FileChangesMonitorStop = s_FileChangesMonitor.FieldType.GetMethod("Stop", BindingFlags.NonPublic | BindingFlags.Instance);


    private static object HttpRuntime

    {

        get

        {

            return s_TheRuntime.GetValue(null);

        }

    }


    private static object FileChangesMonitor

    {

        get

        {

            return s_FileChangesMonitor.GetValue(HttpRuntime);

        }

    }


    public static void StopFileMonitoring()

    {

        s_FileChangesMonitorStop.Invoke(FileChangesMonitor, null);

    }

}


查看完整回答
反对 回复 2019-11-14
  • 3 回答
  • 0 关注
  • 622 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信