如果在 Application_Start 中抛出未处理的异常会发生什么?
...是否会针对下一个请求再次运行 Application_Start 方法?
它是否取决于 ASP.NET 版本、托管服务器版本和/或其他上下文?
我试图确定在那里加载关键程序集是否是一件好事。例如,对于整个应用程序的功能是否至关重要的数据访问组件。无法加载此类程序集将使后续请求变得无用。
... will the Application_Start method be ran again for the next request(s) or not?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个 Web 应用程序只会触发一次 Application_Start ,因此在您的情况下,后续请求不会再次启动。
通常,我更喜欢将一次性启动代码放在 try-catch 内的应用程序启动中,如果出现异常,则设置全局错误标志。在每个 BeginRequest 中,都会检查该标志,如果设置了该标志,则用户将被重定向到自定义错误页面,指示该网站已关闭,请联系管理员。
Application_Start will be fired only once for each web application so in your case, the start will not happen again for subsequent requests.
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.