Asp.Net程序根目录下文件夹操作导致Session失效的解决方案

2021-07-10 01:07

阅读:372

标签:gets   添加   cpi   process   run   解决方案   失效   div   sax   

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失效的解决方案

标签:gets   添加   cpi   process   run   解决方案   失效   div   sax   

原文地址:http://www.cnblogs.com/yuzhihui/p/7091013.html


评论


亲,登录后才可以留言!