添加Global文件,名字不要改
Global类说明:
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.Security; using System.Web.SessionState; namespace WebApplication1 { public class Global : System.Web.HttpApplication { /// <summary> /// 网站启动的时候会被调用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_Start(object sender, EventArgs e) { File.AppendAllText(@"c:\1.txt", DateTime.Now + "Application_Start\r\n"); } /// <summary> /// 某一个session启动的时候会被调用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Session_Start(object sender, EventArgs e) { File.AppendAllText(@"c:\1.txt", DateTime.Now + "Session_Start\r\n"); } /// <summary> /// 当一个请求过来的时候会被调用,html静态文件是iis直接把文件给到浏览器,不经过asp.net引擎处理 /// 所以不会调用Application_BeginRequest方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_BeginRequest(object sender, EventArgs e) { File.AppendAllText(@"c:\1.txt", DateTime.Now + "Application_BeginRequest" + Context.Request.RawUrl + "\r\n"); } protected void Application_AuthenticateRequest(object sender, EventArgs e) { } /// <summary> /// 当web应用程序发生错误的时候会被调用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_Error(object sender, EventArgs e) { File.AppendAllText(@"c:\1.txt", DateTime.Now + "Application_Error" + Context.Error + "\r\n"); } /// <summary> /// 当session结束的时候会被调用,如session超时,设置session 20分钟过期,到了这时间就被调用 /// 只有进程内session,也就是InProc过期的时候才会调用Session_End,进程外session不会调用此方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Session_End(object sender, EventArgs e) { File.AppendAllText(@"c:\1.txt", DateTime.Now + "Session_End\r\n"); } /// <summary> /// 当web应用程序退出的时候会被调用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Application_End(object sender, EventArgs e) { File.AppendAllText(@"c:\1.txt", DateTime.Now + "Application_End\r\n"); } } }
设置session过期时间:
<configuration> <system.web> <sessionState timeout="1"></sessionState> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> </system.web> </configuration>
时间: 2024-10-06 00:39:23