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()的更多相关文章

  1. Effective Java 62 Document all exceptions thrown by each method

    Principle Always declare checked exceptions individually, and document precisely the conditions unde ...

  2. 写出简洁的Python代码: 使用Exceptions(转)

    add by zhj: 非常好的文章,异常在Python的核心代码中使用的非常广泛,超出一般人的想象,比如迭代器中,当我们用for遍历一个可迭代对象时, Python是如何判断遍历结束的呢?是使用的S ...

  3. 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 ...

  4. 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 ...

  5. JMS - Exceptions

    The JMSException JMS defines JMSException as the root class for exceptions thrown by JMS methods. JM ...

  6. Threading in C#

    http://www.albahari.com/threading/ PART 1: GETTING STARTED Introduction and Concepts C# supports par ...

  7. 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 ...

  8. java7 API详解

    Java™ Platform, Standard Edition 7API Specification This document is the API specification for the J ...

  9. java实现谷歌二步验证 (Google Authenticator)

    准备: 一个谷歌二步验证APP,  我用的是ios 身份宝 资料: 1.Google Authenticator 原理及Java实现   //主要参考 https://blog.csdn.net/li ...

随机推荐

  1. Python笔记(二十)_多态、组合

    多态 对于函数中的变量,我们只需要知道它这个变量是什么类,无需确切地知道它的子类型,就可以放心地调用类的方法,而具体调用的这个方法是作用在父类对象还是子类对象上,由运行时该对象的确切类型决定,这就是多 ...

  2. hdu 4001 To Miss Our Children Time( sort + DP )

    To Miss Our Children Time Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Jav ...

  3. topic模式下的收发

    生产者: import pika import sys connection = pika.BlockingConnection(pika.ConnectionParameters( host='lo ...

  4. JVM(3) 之 内存分配与回收策略

    开发十年,就只剩下这套架构体系了! >>>   之前讲过虚拟机中的堆,他是整个内存模型中占用最大的一部分,而且不是连续的.当有需要分配内存的时候,一般有两个方法分配,指针碰撞和空闲列 ...

  5. 【学习总结】认识MVC

    参考链接: 菜鸟教程-MVC模式 CSDN:浅谈MVC架构-你到底有什么本事 目录: 一.什么是MVC 1.概念 MVC全名是Model View Controller,是模型(model)-视图(v ...

  6. k3 cloud成本调整单引入单据后,再做出库成本核算。成本调整单列表已审核的单据消失,非已审核的单据还在,这是出库成本核算设置参数的问题吗?

    存货核算时,会将“期末余额调整”类型的的调整单删除后,再重新产生:因此引入后不要再做出库核算,或者引入其它类型的单据.

  7. React入门-JSX和虚拟dom

    1.JSX理解 举例: const element = <h1>Hello, world!</h1>; 这被称为 JSX,是一个 JavaScript 的语法扩展.建议在 Re ...

  8. JS-04 JS中的函数都是按值传递的

    JS中的函数都是按值传递的 1.传递参数是基本类型 如例子:基本类型传入函数后,函数内部参数生成一个参数副本,把num变量的值赋给num参数,num参数再去参与函数中的运算,但不会影响外面num变量的 ...

  9. ApacheHttpServer修改httpd.conf配置文件

    转自:https://blog.csdn.net/dream1120757048/article/details/77427351 1. 安装完 Apache HTTP Server 之后,还需要修改 ...

  10. ubuntu vim8.1编译安装

    sudo apt-get install libncurses5-dev python-dev python3-dev libgtk-3-dev libatk1.0-dev libbonoboui2- ...