How do I persist session values in ASP.NET?

六眼飞鱼酱① 提交于 2019-12-08 07:00:50

问题


I'm implementing IHttpHandler and IRequiresSessionState and I'm using context.Session but after I set up a value in Session, it's lost in the next request. What can I do to persist the values ?

$.ajax({
        url: "/test.test", 
        type: "POST",
        data: "{'type':'GetStep'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (result) {...}
 });

The second call is similar to this, but the values that get set when I call this function are also lost on the next request.

public void ProcessRequest (HttpContext context)
{
    context.Session ["Game"] = new Game (); // next time it is null
}

How do I persist values in Session state in ASP.NET ?


回答1:


Do you have session state defined in your web.config? Something like this

<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20"/>


来源:https://stackoverflow.com/questions/5245868/how-do-i-persist-session-values-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!