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 ...
随机推荐
- 怎么查看keras 或者 tensorflow 正在使用的GPU
查看keras认得到的GPU from keras import backend as K K.tensorflow_backend._get_available_gpus() Out[28]: [' ...
- Logistic Regression Algorithm解决分类问题
在线性回归算法中,我们看到,在training set中,输入矩阵X与向量y的值都是连续的.所以在二维空间中,我们可以用一条直线去模拟X与y的变化关系,寻找参数向量theta的取值.如根据房屋面积预测 ...
- 《JAVA设计模式》之观察者模式(Observer)
在阎宏博士的<JAVA与模式>一书中开头是这样描述观察者(Observer)模式的: 观察者模式是对象的行为模式,又叫发布-订阅(Publish/Subscribe)模式.模型-视图(Mo ...
- [Linux] 028 源码包安装过程
1. 安装准备 安装 C 语言编译器 下载源码包 如:apache 相应源码包下载地址 2. 安装注意事项 源代码保存位置:/usr/local/src 软件安装位置:/usr/local 如何确定安 ...
- 安装go版本
下载地址(官网):https://golang.org/dl/ 下载地址(国内):https://dl.gocn.io/ 想编译GO,必须先有一个GO的编译器. 创建GO的编译器:[root@node ...
- android测试开发概念
一:测试分类 1.分类概览 按测试阶段划分: 单元测试 集成测试 系统测试 验收测试 按是否覆盖源代码: 黑盒测试: 功能测试: 界面测试 逻辑测试 安装测试 应用性测试 兼容性测试 性能测试: 稳定 ...
- jvm性能监控(3)-jdk自带工具 jps jstack jmap
一.概要: jps -l 查看现有的java进程 jps -l 显示所有正在运行的java进程id jstack 查看Java线程 jstack -l pid; 做thread dump ...
- java_第一年_JavaWeb(8)
前面说到,JSP在运行时会被编译成Servlet源代码,通过_jspServlet方法处理请求,此时该方法会传递和提供9个与web开发相关的对象进行使用,开发人员在JSP页面通过对这些变量即可引用这9 ...
- 报错: no such table:django_session解决方式
如果出现这个错误 “no such table:django_session” 这个错误跟Session的机制有关, 既然要从Web服务器端来记录用户信息, 那么一定要有存放用户session id对 ...
- 安卓构架组件——向项目添加组件(Adding Components to your Project)
在开始之前,建议阅读 应用架构指南. Before getting started, we recommend reading the Architecture Components Guide to ...