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. 【ABAP系列】SAP ABAP基础-SQL的嵌套使用

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP基础-SQL的嵌 ...

  2. Ubuntu下使用boost例子

    http://blog.csdn.net/dotphoenix/article/details/8459277 1. 安装boost库 sudo apt-get install libboost-al ...

  3. SQLServer2008查询时对象名无效

    情况一:如果表名是关键字,查询时把表名括起来,不作为关键字使用 情况二:看左上角显示的是否是master,这是数据库的默认系统库,点选这个改成自己的即可

  4. jmeter 添加header

    接口说明文档: article.fetch(通用转码服务) 通用转码服务,获取任意 url 的正文以及 title 等基本信息,仅支持 post 方法请求. 参数 参数 类型 是否必须 示例 其它说明 ...

  5. Spring Security 04

    转至:Elim的博客http://elim.iteye.com/blog/2161648 Filter Porxy DelegatingFilterProxy DelegationFilterProx ...

  6. Spring自动装配之依赖注入(DI)

    依赖注入发生的时间 当Spring IOC 容器完成了Bean 定义资源的定位.载入和解析注册以后,IOC 容器中已经管理类Bean定义的相关数据,但是此时IOC 容器还没有对所管理的Bean 进行依 ...

  7. df认识

    import pandas as pd #自己创建一个df df = pd.DataFrame({ ,,], 'col2':["zs",'li','zl'], 'col3':[3. ...

  8. [Codeforces 464E] The Classic Problem(可持久化线段树)

    [Codeforces 464E] The Classic Problem(可持久化线段树) 题面 给出一个带权无向图,每条边的边权是\(2^{x_i}(x_i<10^5)\),求s到t的最短路 ...

  9. Source Insight symbol not found

    使用SourceInsight查看源代码时,发现点击查看相关类型时,无法关联到其代码,出现 symbol not found, 然而明明在我的头文件有定义的 网上查了一下主要是因为新建工程导入文件后, ...

  10. C# json格式的序列化与反序列化

    使用C#,来序列化对象成为Json格式的数据,以及如何反序列化Json数据到对象 Json[javascript对象表示方法],它是一个轻量级的数据交换格式,我们可以很简单的来读取和写它,并且它很容易 ...