【发布时间】:2011-02-07 14:41:29
【问题描述】:
如果我的项目使用不正确、不完整或丢失的连接字符串部署,我希望应用程序启动检查数据库连接,如果没有,将所有请求定向到某种 DatabaseConnectionError 页面,什么是我的选择?我认为没有适合此错误的特定 http 错误代码,而且我目前没有使用 web.config 来定义所有错误的通用 catch all。
我有
/// <summary>
/// from http://www.davidjuth.com/asp-net-mvc-error-handler.aspx
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
protected void Application_Error(object sender, EventArgs args)
{
Exception ex = Server.GetLastError();
using (var crashFile = new System.IO.StreamWriter(Server.MapPath("~/App_Data/Crash_" + DateTime.UtcNow.ToString("yyyyMMdd") + ".log")))
crashFile.WriteLine("<crash><time>" + DateTime.UtcNow.TimeOfDay.ToString() + "</time><url>" + HttpContext.Current.Request.Url + "</url><exception>" + ex.ToString() + "</exception></crash>");
}
但它似乎不允许我用页面响应请求。
【问题讨论】:
标签: asp.net-mvc error-handling connection-string database-connection web-config