Dealing with exceptions thrown in Application_Start()
https://blog.richardszalay.com/2007/03/08/dealing-with-exceptions-thrown-in-application_start/
One annoying problem I've noticed in the past is that if an exception is thrown in Application_Start() the application does not restart, resulting in subsequent requests going through to the application (aspx pages and other handlers) without the Application_Start() actions happening. This can be particularly annoying as the errors that result on the pages of the site do not tell you why Application_Start threw an exception to begin with.
Luckily there is a simple solution, and it involves using HttpRuntime.UnloadAppDomain. If you call UnloadAppDomain the application will reset and the next request will start it up again, causing Application_Start to occur again. This will allow you diagnose the error that is occuring in Application_Start and thus let you fix the problem.
Below is a sample Application_Start method:
void Application_Start(object sender, EventArgs e)
{
try
{
// Some important startup stuff that must happen
}
catch
{
HttpRuntime.UnloadAppDomain(); // Make sure we try to run Application_Start again next request
throw; // Rethrow whatever was caught
}
}
https://docs.microsoft.com/en-us/dotnet/api/system.web.httpruntime.unloadappdomain?view=netframework-4.8
Terminates the current application. The application restarts the next time a request is received for it.
Remarks:
UnloadAppDomain
is useful for servers that have a large number of applications that infrequently receive requests. Rather than keep application resources alive for the lifetime of the process, UnloadAppDomain
allows programmatic shutdown of unused applications.
Dealing with exceptions thrown in Application_Start()的更多相关文章
- Effective Java 62 Document all exceptions thrown by each method
Principle Always declare checked exceptions individually, and document precisely the conditions unde ...
- 写出简洁的Python代码: 使用Exceptions(转)
add by zhj: 非常好的文章,异常在Python的核心代码中使用的非常广泛,超出一般人的想象,比如迭代器中,当我们用for遍历一个可迭代对象时, Python是如何判断遍历结束的呢?是使用的S ...
- Thinking in Java,Fourth Edition(Java 编程思想,第四版)学习笔记(十二)之Error Handling with Exceptions
The ideal time to catch an error is at compile time, before you even try to run the program. However ...
- NDK(5) Android JNI官方综合教程[JavaVM and JNIEnv,Threads ,jclass, jmethodID, and jfieldID,UTF-8 and UTF-16 Strings,Exceptions,Native Libraries等等]
JNI Tips In this document JavaVM and JNIEnv Threads jclass, jmethodID, and jfieldID Local and Global ...
- JMS - Exceptions
The JMSException JMS defines JMSException as the root class for exceptions thrown by JMS methods. JM ...
- Threading in C#
http://www.albahari.com/threading/ PART 1: GETTING STARTED Introduction and Concepts C# supports par ...
- Async/Await - Best Practices in Asynchronous Programming z
These days there’s a wealth of information about the new async and await support in the Microsoft .N ...
- java7 API详解
Java™ Platform, Standard Edition 7API Specification This document is the API specification for the J ...
- java实现谷歌二步验证 (Google Authenticator)
准备: 一个谷歌二步验证APP, 我用的是ios 身份宝 资料: 1.Google Authenticator 原理及Java实现 //主要参考 https://blog.csdn.net/li ...
随机推荐
- json字符串格式
private static final String COMPLEX_JSON_STR = "{" + "\"teacherName\":\&quo ...
- ES6 find 和 filter 的区别
ES6 find 和 filter 的区别 : 遇到个功能是要分类就想说在前端过滤,不要从查数据库的时候过滤了.然后就想说除了filter还有啥好用的 发现有个find,测试一番之后发现 const ...
- [Codeforces600E] Lomsat gelral(树上启发式合并)
[Codeforces600E] Lomsat gelral(树上启发式合并) 题面 给出一棵N个点的树,求其所有子树内出现次数最多的颜色编号和.如果多种颜色出现次数相同,那么编号都要算进答案 N≤1 ...
- python学习第十六天集合的关系测试
在做数据分析的时候,要对一个集合分析,而且分析多个集合的之间的关系分析,那么用传统的循环的比较麻烦,集合提供很多方法,很容易比较多个集合的关系,并集,交集,差集,对称差集等. n1={1,2,4,6} ...
- Page.IsPostBack
ASP.NET页面的执行顺序说明:Page_Init(页面初始化引发的事件)——Page_Load(加载页面时引发的事件)——ControlEvent(服务器控件引发的事件)——Page_UnLoad ...
- Ioc和DI之间的关系(依赖注入的核心概念)
1.开篇闲话 由于之前做的很多项目都没接触到这个,后来到了另一个公司,他们的代码结构是基于领域驱动设计的,其中里面的对象都是通过依赖注入方式(Sprint.NET)实现的,也大致了解了哈,在网上搜了些 ...
- 2018-4-30-win2d-CanvasRenderTarget-vs-CanvasBitmap
title author date CreateTime categories win2d CanvasRenderTarget vs CanvasBitmap lindexi 2018-04-30 ...
- smbmount - 装载一个 smbfs 文件系统
总览 SYNOPSIS smbmount {service} {mount-point} [-o options] 描述 DESCRIPTION smbmount 可以装载一个Linux SMB文件系 ...
- 一、Iframe
一.Iframe 自适应iframe的高 <!-- frameborder :设置iframe的边框 scrolling:设置iframe的滚动条 src:设置iframe的路径 onload: ...
- 【LeetCode】设计题 design(共38题)
链接:https://leetcode.com/tag/design/ [146]LRU Cache [155]Min Stack [170]Two Sum III - Data structure ...