It has become common practice to perform tasks during an ASP.NET applications start up process. These tasks may include registering routes, configuring filters, wiring up third party dependencies, and so much more. Here is the default ASP.NET MVC application startup code pulled from the sample.

protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}

These tasks are crucial to the function of the application, but they don't always execute cleanly. Exceptions in the startup process can mean the application never got a change to wire up exception handlers. This can make it difficult to debug issues in production, causing us to turn customErrors off.

<customErrors mode="Off" />

To insure you capture application startup exceptions, remember to implement Application_Error.

private void Application_Error(object sender, EventArgs e)
{
// a static boolean at the application level
if (FailedToStartUp)
{
// Step 1 : write to a dependable logging storage
// option 1 : Trace
// option 2 : Raygun
// option 3 : Filesystem // Step 2 : Redirect to non-app based Error page
// obviously needs to exist outside your app
// since it failed to startup
}
}

Now we should get a log message that lets us know what the exception is, and additionally our users get to see an error page that isn't of the red and yellow variety. Note, it may be the default error logging mechanism that we've chosen that is causing our application failure. I recommend having a fallback logging mechanism if possible; Trace is a safe bet.

 

Khalid Abuhakmeh – Software Developer and All Around Nice Guy

原文链接:http://www.khalidabuhakmeh.com/capturing-asp-net-application-startup-exceptions

Capturing ASP.NET Application Startup Exceptions的更多相关文章

  1. ASP.NET Core 1.0 入门——Application Startup

    var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...

  2. Examining Application Startup in ASP.NET 5

    By Steve Smith  June 23, 2015 ASP.NET 5 differs from previous versions of ASP.NET in many ways. Gone ...

  3. ASP.NET Application Life Cycle

    The table in this topic details the steps performed while an XAF ASP.NET application is running. Not ...

  4. ASP.NET Application and Page Life Cycle

    ASP.NET Application Life Cycle Overview for IIS 7.0 https://msdn.microsoft.com/en-us/library/bb47025 ...

  5. Asp.netCore 的Startup 不继承接口

    有一个问题: Asp.netCore 的Startup 要实现 Config 和ConfigServie 方法, 为什么不接口约束呢. 进入源码: // // 摘要: // /// Specify t ...

  6. How to increase timeout for your ASP.NET Application ?

    How to increase timeout for your ASP.NET Application ? 原文链接:https://www.techcartnow.com/increase-tim ...

  7. Debug your ASP.NET Application while Hosted on IIS

    转摘:http://www.codeproject.com/Articles/37182/Debug-your-ASP-NET-Application-while-Hosted-on-IIS This ...

  8. ASP.NET Core Startup类 Configure()方法 | ASP.NET Core 中间件详细说明

    ASP.NET Core 程序启动过程如下 目录 Startup 类 Configure() 方法 中间件 使用中间件 Configure 方法 的参数 IApplicationBuilder Ext ...

  9. ASP.NET Application,Session,Cookie和ViewState等对象用法和区别 (转)

    在ASP.NET中,有很多种保存信息的内置对象,如:Application,Session,Cookie,ViewState和Cache等.下面分别介绍它们的用法和区别. 方法 信息量大小 作用域和保 ...

随机推荐

  1. HashMap源码分析(基于JDK1.6)

      在Java集合类中最常用的除了ArrayList外,就是HashMap了.本文尽自己所能,尽量详细的解释HashMap的源码.一山还有一山高,有不足之处请之处,定感谢指定并及时修正. 在看Hash ...

  2. 解决安装Weblogic domain卡住问题(Primeton BPS)

    这两天一直有一个问题困扰我,在suse10+weblogic(920,923,100,103)上安装bpm产品失败.有些版本是创建domain的时候卡在create security informat ...

  3. Nginx 教程示例

    https://www.cnblogs.com/jingmoxukong/p/5945200.html

  4. 对于global的介绍

    抄自http://veniceweb.googlecode.com/svn/trunk/public/daily_tech_doc/erlang_global_20091109.txt 1. 介绍:这 ...

  5. iPhone之IOS5内存管理(ARC技术概述)

    ARC(Automatic Reference Counting )技术概述 此文章由Tom翻译,首发于csdn的blog,任何人都可以转发,但是请保留原始链接和翻译者得名字.多谢! Automati ...

  6. MyBatis 一对一(OneToOne)__SELECT

    1.创建SQL脚本: CREATE TABLE t_person(  id int(3) not null auto_increment,  name varchar(20) default null ...

  7. PL/SQL 训练09--面向对象

    ---对象基本声明.实现.使用--对象类型,类似与JAVA中的类,通俗的讲,就是捆绑了相关函数和过程的记录类型. ---对象声明 --create type 创建一个对象类型的规范部分 create ...

  8. Spring MVC启动时初始化的几个常用方法

    Spring-MVC的应用中,要实现类似的功能,主要是通过实现下面这些接口(任选一,至少一个即可) 一.ApplicationContextAware接口 +? 1 2 3 4 5 6 7 8 9 p ...

  9. IDA Pro 权威指南学习笔记(五) - IDA 主要的数据显示窗口

    在默认配置下,IDA(从 6.1 版开始)会在对新二进制文件的初始加载和分析阶段创建 7 个显示窗口 3 个立即可见的窗口分别为 IDA-View 窗口.函数窗口和消息输出窗口 可以通过 View - ...

  10. python's twenty-second day for me 封装,property方法

    面对对象的三大特性:继承,多态,封装. 函数和属性装到了一个非全局的命名空间----封装. 封装: 在类中,静态属性,方法,对象属性都可以变成私有的,只需要在这些名字前加上‘__’(双下划线). 在类 ...