1 二个方法比较重要
//网站运行后只会运行一次 不管换不换浏览器都不回执行
protected void Application_Start(object sender, EventArgs e)
{
HttpContext.Current.Application["web"] = "我只会执行一次" + DateTime.Now;
//在页面中输出的时候
Response.Write(Application["web"].ToString());
}
/// <summary>
/// 出现页面错误的
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Session_Start(object sender, EventArgs e)
{//记录错误日志
HttpApplication app = sender as HttpApplication;
string path = app.Context.Server.MapPath("/2.txt");
System.IO.File.AppendAllText(path, HttpContext.Current.Server.GetLastError().Message);
}