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.

  1. protected void Application_Start()
  2. {
  3. AreaRegistration.RegisterAllAreas();
  4. FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
  5. RouteConfig.RegisterRoutes(RouteTable.Routes);
  6. BundleConfig.RegisterBundles(BundleTable.Bundles);
  7. }

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.

  1. <customErrors mode="Off" />

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

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

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. git diff的使用

    有时候可能睡觉时候忘记关电脑了,然后不小心触碰到键盘上某个神秘的按钮了,然后自己也不知道就提交了 就可能很悲剧 那么有时候不知道自己是否改变了哪些文件的内容 这时候就需要用到git diff git ...

  2. 上一步是硬件描述语言,下一步是FPGA

    上一步是硬件描述语言,下一步是FPGA. 学习了硬件描述语言(Verilog或者VHDL)之后,FPGA该如何继续. 世上没有捷径,每一步都得踏踏实实的走.学习FPGA也是这样,在有了硬件描述语言的基 ...

  3. 数据的持久性存储(二)——CoreData(附Demo)

    CoreData是一款稳定.功能全面的持久性工具.(本文参考iphone开发3所写,比较简要,需详细了解可以参考iphone开发3) 首先创建一个新的项目CoraData,记得勾选Use Core D ...

  4. HAProxy安装配置用于TCP的负载均衡

    HaProxy介绍 Haproxy是一个开源的高性能的反向代理或者说是负载均衡服务软件之一,它支持双机热备.虚拟主机.基于TCP和HTTP应用代理等功能.其配置简单,而且拥有很好的对服务器节点的健康检 ...

  5. PHP面向对象深入研究之【对象生成】

    对象 看个例子 <?php abstract class Employee { // 雇员 protected $name; function __construct( $name ) { $t ...

  6. 用python编写简单爬虫

    需求:抓取百度百科python词条相关词条网页的标题和简介,并将数据输出在一个html表格中 入口页:python的百度词条页 https://baike.baidu.com/item/Python/ ...

  7. springboot成神之——拦截器

    本文介绍spring boot拦截器 创建拦截器类LogInterceptor.java 创建拦截器类OldLoginInterceptor.java 拦截器配置类WebMvcConfig.java ...

  8. python实现文件加密

    前言: 想实现批量文件加密,可惜批量.展时没有思路 0x1 没有加密前的图片 加密后!!! !!!打不开了 0x02: 代码 import hashlib def get_sha1(f): xd=op ...

  9. in not in 和 null , in 判断范围中可以包含null,而not in判断不能包括null

    oracle中,任何字符串与null比较得到的结果都是null,而 oracle的判断条件为null时就退出判断(?) 因此判断某个字符串是否在一个集合中时,not in 和 in的结果完全不一样,如 ...

  10. svn锁定问题解决

    问题描述: 今天遇到svn文件被某个人锁定,搞得全部人都不能提交更新. 解决方法一: 首先,先定位到工程目录下,然后使用如下命令查看是否有锁 find . | grep ".svn/lock ...