Asp.Net程序目录下文件夹或文件操作导致Session失效的解决方案
程序员文章站
2023-10-30 15:05:52
1、配置web.config
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(object sender, 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失效的解决方案,希望对大家有所帮助