Capturing ASP.NET Application Startup Exceptions
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的更多相关文章
- ASP.NET Core 1.0 入门——Application Startup
var appInsights=window.appInsights||function(config){ function r(config){t[config]=function(){var i= ...
- 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 ...
- ASP.NET Application Life Cycle
The table in this topic details the steps performed while an XAF ASP.NET application is running. Not ...
- 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 ...
- Asp.netCore 的Startup 不继承接口
有一个问题: Asp.netCore 的Startup 要实现 Config 和ConfigServie 方法, 为什么不接口约束呢. 进入源码: // // 摘要: // /// Specify t ...
- How to increase timeout for your ASP.NET Application ?
How to increase timeout for your ASP.NET Application ? 原文链接:https://www.techcartnow.com/increase-tim ...
- 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 ...
- ASP.NET Core Startup类 Configure()方法 | ASP.NET Core 中间件详细说明
ASP.NET Core 程序启动过程如下 目录 Startup 类 Configure() 方法 中间件 使用中间件 Configure 方法 的参数 IApplicationBuilder Ext ...
- ASP.NET Application,Session,Cookie和ViewState等对象用法和区别 (转)
在ASP.NET中,有很多种保存信息的内置对象,如:Application,Session,Cookie,ViewState和Cache等.下面分别介绍它们的用法和区别. 方法 信息量大小 作用域和保 ...
随机推荐
- C#合成解析XML与JSON
http://www.xuanyusong.com/archives/1901 XML与JSON在开发中非常重要, 其实核心就是处理字符串.一个是XML的字符串一个是JSON的字符串,尤其是在处 ...
- 安装ruby-pg报错解决
ruby用pgsql做orm的时候,需要安装ruby-pg库,默认编译安装会提示缺少xx头文件 max下,我用的傻瓜式pgsql.app gem install pg -- --with-pg-con ...
- android欢迎页
在进入程序后,会在一个页面停留几秒然后自动跳转到程序主界面,这个页面就是欢迎页. 首先新建个java文件,给他起名叫做WelcomeActivity 在里面我们通过一个匿名类new Handler,在 ...
- java成神之——Fork/Join基本使用
Fork/Join 大任务分小任务,小任务结果合并 ForkJoinPool pool = new ForkJoinPool(); RecursiveTask<Integer> task1 ...
- linux安装xgboost
在学校服务器上安装xgboost,事先我已经安装了anaconda,但是因为师兄已经装了python所以没加入到path. 网上的方法一般都要编译,另外官方的下载方法要联网..总之出了一堆错,最终还是 ...
- Linux进阶路线
初级:熟练使用命令.熟悉Shell编程.能配置简单的服务,清楚各类服务相关的配置文件的位置, 能看懂并可修改系统提供的配置脚本(/etc/*.*)把/etc目录下面常用的配置你都搞懂,把 /bin / ...
- Mycat实战之日志分析
环境搭建参见之前发的一篇:http://www.cnblogs.com/chinesern/p/7667106.html 1修改log4j.xml 配置增加其他级别调试以及验证是否自动加载 cat / ...
- AMFObject 数据格式浅析
amf.h中关于 AMFObject 是这样的定义的: typedef struct AMFObject { int o_num; struct AMFObjectProperty *o_props; ...
- 移植RT2870无线网卡驱动到s3c2416
公司项目要用到usb无线网卡,芯片是ralink的RT2870.以下是将其驱动移植到s3c2416的步骤. 1.下载驱动源码,雷凌官网的下载地址是: http://www.ralinktech.com ...
- 在java中RandomAccessFile类的作用:对指定文件可以进行读写的操作