Home > Backend Development > C#.Net Tutorial > How to solve Session failure in Asp.Net?

How to solve Session failure in Asp.Net?

零下一度
Release: 2017-07-02 10:34:20
Original
1985 people have browsed it

This article mainly introduces the solution to Session caused by folder or file operations in the Asp.Net program directory. Friends in need can refer to the following

1. Configure 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>
Copy after login

2. Add startup ASP.NET in Global.asax StatusService code

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

The above is the detailed content of How to solve Session failure in Asp.Net?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template