如果在Application_Start中抛出未处理的异常会发生什么? [英] What happens if an unhandled exception is thrown in Application_Start?

查看:593
本文介绍了如果在Application_Start中抛出未处理的异常会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

...是否会为下一个请求再次运行Application_Start方法?

... will the Application_Start method be ran again for the next request(s) or not?

它是否依赖于ASP.NET版本,托管服务器版本和/或其他上下文?

Does it depend on ASP.NET version, hosting server version and/or other context?

我试图确定在那里加载关键程序集是否是一件好事。例如,对整个应用程序的运行至关重要的数据访问程序集。无法加载此类程序集会使后续请求无效。

I am trying to determine if it's a good thing to load critical assemblies there or not. For example data access assemblies which are vital to the functioning of the whole application or not. Failure to load such assembly would make subsequent requests useless.

推荐答案

Application_Start将仅针对每个Web应用程序触发一次,因此在您的情况下,后续请求不会再次开始。

Application_Start will be fired only once for each web application so in your case, the start will not happen again for subsequent requests.

通常,我更喜欢在try-catch中的应用程序启动时放入一次启动代码,如果有的话然后设置全局错误标志。在每个BeginRequest中,将检查该标志,如果已设置,则会将用户重定向到自定义错误页面,指示该站点已关闭,请联系管理员。

Typically, I prefer to put one time start-up code in the application start within try-catch and if there is an exception then set the global error flag. In each BeginRequest, the flag is checked and if it is set, user is redirected to a custom error page indicating the site is down and please contact the administrator.

这篇关于如果在Application_Start中抛出未处理的异常会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆