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. ASP.NET Cache缓存的使用

    ASP.NET Cache是提升系统性能的重要方法,它使用了“最近使用”原则(a least-recently-used algorithm).在数据库访问中经常会用到Cache保存数据库数据. 1. ...

  2. JAVA设计模式:静态代理

    一.概念代理模式是常用的Java 设计模式,它的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类,以及事后处理消息等.代理类与委托类之间通常会存在关联关 ...

  3. Angular2配置文件详解

    初学接触Angular2的时候,通过ng new your-project-name 命令生成一个工程空壳,本文来介绍下每个文件的作用及含义. 先来看看src的文件目录: 文件详解 File 文件 P ...

  4. yii2史上最简单式安装教程,没有之一(转)

    测试说明:按照文章下载文件,虽然是tgz文件,用winrar解压,在CMD中运行init.bat文件. 既然是安装Yii,我们先去官网下载一份Yii的高级模版,什么,你说打开页面乱七八糟的英文字母你看 ...

  5. unidac 执行Execute后取得受影响行数。

    unidac 执行Execute后取得受影响行数. uniQuery2.SQL.Text := mmo2.Text; uniQuery2.Execute; mmo1.Lines.Add(Format( ...

  6. ES之一:Elasticsearch6.4 windows安装 head插件ik分词插件安装

    准备安装目标:1.Elasticsearch6.42.head插件3.ik分词插件 第一步:安装Elasticsearch6.4 下载方式:1.官网下载 https://www.elastic.co/ ...

  7. 反射getattr,hasattr,setattr,delattr

    通过字符串映射或修改程序运行时的状态.属性.方法, 有以下4个方法 getattr(object, name_str, default=None) 根据字符串name_str去获取obj对象里的方法内 ...

  8. Linux操作系统下的多线程编程详细解析----条件变量

    条件变量通过允许线程阻塞和等待另一个线程发送信号的方法,弥补了互斥锁(Mutex)的不足. 1.初始化条件变量pthread_cond_init #include <pthread.h> ...

  9. U-boot分析与移植(1)----bootloader分析

    一.Boot Loader 概念 就是在操作系统内核运行之前运行的一段小程序.通过这段小程序,我们可以初始化硬件设备.建立内存空间的映射图,从而将系统的软硬件环境带到一个合适的状态,以便为最终调用操作 ...

  10. DFT的理解

    在以前学习的离散傅立叶变换(DFT),总是不能理解只是知道公式 X(k) = Σx(n) * WNnk    ,也不知道如何得来的. 现在可以聊聊了,因为最近在使用MATLAB实际的操作了所以比以前了 ...