Asp.Net程序根目錄下文件夾操作導致Session失效的解決方案
阿新 • • 發佈:2017-06-28
rgs get bject process simple exce cep clas .net
1、配置web.config
<system.web> <sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="40"/> </system.web>
2、在Global.asax中添加啟動啟動ASP.NET 狀態服務代碼
void Application_Start(objectsender, EventArgs e) { // 在應用程序啟動時運行的代碼 try { //啟動ASP.NET 狀態服務 string g_serviceName = "aspnet_state"; System.ServiceProcess.ServiceController[] serviceControllers = System.ServiceProcess.ServiceController.GetServices();foreach (System.ServiceProcess.ServiceController service in serviceControllers) { if (service.ServiceName == g_serviceName) { if (service != null && service.Status != System.ServiceProcess.ServiceControllerStatus.Running) { service.Start(); SimpleLogHelper.WriteError(g_serviceName+ "服務已開啟"); } else { if (service == null) { SimpleLogHelper.WriteError(g_serviceName + "服務未安裝"); } else { SimpleLogHelper.WriteError(g_serviceName + "服務正在運行..."); } } break; } } } catch (Exception ex) { SimpleLogHelper.WriteError(ex.ToString()); } }
Asp.Net程序根目錄下文件夾操作導致Session失效的解決方案