1、配置web.config
1
2
3
4
|
<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 状态服务代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
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失效的解决方案,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:http://www.cnblogs.com/yuzhihui/archive/2017/06/28/7091013.html