global中Application

protected void Application_Start(object sender, EventArgs e)
{
HttpContext.Current.Application["webName"] = "哇哈哈哈~~~~~~~~~~" + DateTime.Now;
}

/// <summary>
/// 当整个网站 的任意页面 出现异常时 会执行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Application_Error(object sender, EventArgs e)
{
//记录错误日志
HttpApplication app = sender as HttpApplication;
string errPath = app.Context.Request.MapPath("/err.txt");
System.IO.File.AppendAllText(errPath, HttpContext.Current.Server.GetLastError().Message);
}

posted @ 2017-06-16 09:15  一杯水M  阅读(252)  评论(0)    收藏  举报