微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Asp.Net中Session失效是怎么解决的?

这篇文章主要介绍了Asp.Net程序目录下文件夹或文件操作导致Session失效的解决方案,需要的朋友可以参考下

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());
    }
  }

原文地址:https://www.jb51.cc/csharp/1193733.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐