Application_Start 中出现间歇性异常 - 如何取消启动应用程序?
在我们的 Application_Start
事件处理程序中,我们正在执行一些由于文件锁定问题而间歇性失败的操作。在这种情况下,我们希望将应用程序返回到“未启动”状态。
我的意思是,用户将看到一个错误页面,然后下次用户访问该网站时,Application_Start
事件将再次被触发。
我们使用 ASP.NET 3.5、WebForms 和 MVC。
In our Application_Start
event handler we're performing some actions that intermittently fail due to file locking issues. In this scenario we would like to return the application to an "un-started" state.
By this I mean that the user will be shown an error page, and then the next time a user hits the site the Application_Start
event will be fired again.
We're using ASP.NET 3.5, WebForms and MVC.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AppDomain.Unload 提供您正在寻找的内容,但我不会推荐它。
有很多收获;以编程方式拆除应用程序域并非没有其自身的一系列问题(即,如果线程在本机代码中被阻止,您可能会看到 CannotUnloadAppDomainException),并且通常是一个糟糕的设计,IMO。
你试图做的事情是非常非常规的;我会一起重新考虑这个方法。如果您只需要在应用程序域级别执行一些代码,那么有很多更好的方法可以做到这一点,例如静态或 HttpRuntime 缓存中的标志。只需注意网络花园和并发场景。
祝你好运。
AppDomain.Unload offers what you're looking for, but I wouldn't recommend it.
There are lots of catches; tearing down an app domain programmatically is not without its own set of issues (i.e. if a thread's blocked in native code you may see a CannotUnloadAppDomainException) and is generally a poor design, IMO.
What you're attempting to do is highly unconventional; I would reconsider the approach all together. If you just need to execute some code once at the app domain level, there are lots of better ways to do it, like statics for instance or a flag in the HttpRuntime cache. Just mind the web-garden and concurrency scenarios.
Good luck.
我非常确定没有办法从应用程序内退出/强制停止 webForms 应用程序。然而,阻止应用程序启动的一种不明智的方法是在 application_start 中生成未处理的错误。这将阻止启动发生,并且在下次访问您的 webForms 应用程序时,application_start 将再次尝试。
I'm pretty sure that there is no way to quit/force stop an webForms application from within the application. However, an ungentle way to prevent the application from starting is to generate an unhandled error within your application_start. This will prevent start up from happening and upon the next hit to your webForms app, the application_start will try again.