Solution of session invalidation caused by folder or file operation in ASP. Net program directory

Time:2021-7-20

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>

2. Add asp.net status service code in global.asax

void Application_Start(object sender, EventArgs e)
  {
    //Code that runs when the application starts
    try
    {
      //Start asp.net state service
      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 + "service started");
          }
          else
          {
            if (service == null)
            {
              SimpleLogHelper.WriteError(g_ Servicename + "service not installed");
            }
            else
            {
              SimpleLogHelper.WriteError(g_ Servicename + "service running...);
            }
          }
          break;
        }
      }
    }
    catch (Exception ex)
    {
      SimpleLogHelper.WriteError(ex.ToString());
    }
  }

The above is the solution of session failure caused by folder or file operation in ASP. Net program directory introduced by Xiaobian. I hope it can help you. If you have any questions, please leave me a message and Xiaobian will reply you in time. Thank you very much for your support to developer!