Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# I';当配置文件如下所示时,我遇到了会话丢失问题:_C#_Session - Fatal编程技术网

C# I';当配置文件如下所示时,我遇到了会话丢失问题:

C# I';当配置文件如下所示时,我遇到了会话丢失问题:,c#,session,C#,Session,当配置文件如下所示时,我遇到了会话丢失问题: <sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424" cookieless="UseCookies" timeout="30"/> 在我的错误页面上,我无法访问会话密钥,因此错误页面显示空白消息;我得到的在特定的sessionKey上抛出了一个类型为System.Web.HttpException的异常异常

当配置文件如下所示时,我遇到了会话丢失问题:

<sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424"
              cookieless="UseCookies" timeout="30"/>

在我的错误页面上,我无法访问会话密钥,因此错误页面显示空白消息;我得到的
在特定的sessionKey上抛出了一个类型为System.Web.HttpException的异常
异常。

要用SessionState的StateServer模式解决这个问题,您应该处理页面上的每个错误;您可以创建一个基类,该基类继承自system.web.page并获取错误,然后清除服务器错误,并允许该页面的请求在会话中提交更改以供以后使用

有关StateServer模式的更多信息,请查看以下链接:


我在这里看不到任何问题,但我想答案在这里。
void Application_Error(object sender, EventArgs e)
{
    var lastExp = HttpContext.Current.Server.GetLastError();
    if (lastExp != null )
    {
        var expHelper = new ExceptionHelper();

        Session["ErrorMessage"] = lastExp ;

        if (exp != null)
        {                   
            Server.ClearError();
            this.Response.Redirect(ErrorPage.VirtualPath, true);                   
        }              
    }          
}