ASP.NET Web Service中使用Session 及 Session丢失解决方法 续
1、关于Session丢失问题的说明汇总,参考这里
2、在Web Servcie中使用Session,需要对Web Method做如下处理
[WebMethod(EnableSession = true)]
public void usingSession()
{
Session["Name"] = "Name";
}
public void usingSession()
{
Session["Name"] = "Name";
}
如果不加EnableSession = true,在Web Service中是不能使用Session的。
3、这里说一下使用mode="StateServer"解决Session丢失问题的配置:
1)首先在Windows服务中启用 asp.net State Service,这个服务默认被设置为手动启动
2)在web.config中做如下配置
<system.web>
<!--其他配置信息-->
<sessionState timeout="200000" cookieless="false" mode="StateServer"></sessionState>
</system.web>
<!--其他配置信息-->
<sessionState timeout="200000" cookieless="false" mode="StateServer"></sessionState>
</system.web>
timeout自己根据需要设置,关键是要配置这两个属性cookieless="false" mode="StateServer",cookieless默认为false,所以这个属性可以去掉。
如果cookieless设置为true,URL中会包含会话ID,如:http://localhost:4555/WebSite/(S(dmb2qpn4m2x3cj55pzwcvh55))/index.html。此时Web Service中将无法正常使用Session。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步