您的位置:首页 > 编程语言 > ASP

Global文件的作用

2016-03-17 21:40 411 查看
该文件必须放在网站的根目录下。

public class Global : System.Web.HttpApplication

//      以下代码是关于Global文件的执行,第一个方法,是找到Global文件,并且编译成一个类型
//_theApplicationFactory.EnsureInited();
//  _theApplicationFactory.EnsureAppStartCalled(context);//确保Global文件中Application_Start方法被执行而且只执行一次。
{
// 整个WEB应用程序的入口。相当于Main函数.该方法只执行一次,当WEB应用程序第一次启动时,执行该方法,后续请求其它页面该方法不在执行。该方法中一般完成对整个网站的初始化。
protected void Application_Start(object sender, EventArgs e)
{

}
// 开启会话的时候执行该方法
protected void Session_Start(object sender, EventArgs e)
{
//统计访问人数.
//访问人数+1.
}

protected void Application_BeginRequest(object sender, EventArgs e)
{

}
// context.AcquireRequestState  也可以在这里写这个方法 用来代替HttpModuleHelper类实现Session 过滤
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{

}
// 注意的方法。该方法会捕获程序中没有处理的异常。并且将捕获的异常信息写到日志中。
protected void Application_Error(object sender, EventArgs e)
{
HttpContext.Current.Server.GetLastError();//捕获异常信息.
}
// 会话结束的时候执行该方法。
protected void Session_End(object sender, EventArgs e)
{

}
// 整个应用程序结束的时候执行。
protected void Application_End(object sender, EventArgs e)
{

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp-net