首页 > Web开发 > 详细

ASP.NET Web Service中使用Session 及 Session丢失解决方法 续

时间:2014-12-12 11:16:34      阅读:296      评论:0      收藏:0      [点我收藏+]
原文:ASP.NET Web Service中使用Session 及 Session丢失解决方法 续

1、关于Session丢失问题的说明汇总,参考这里

2、在Web Servcie中使用Session,需要对Web Method做如下处理

[WebMethod(EnableSession = true)]
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>

 

   timeout自己根据需要设置,关键是要配置这两个属性cookieless="false" mode="StateServer",cookieless默认为false,所以这个属性可以去掉。

 如果cookieless设置为true,URL中会包含会话ID,如:http://localhost:4555/WebSite/(S(dmb2qpn4m2x3cj55pzwcvh55))/index.html。此时Web Service中将无法正常使用Session。

 

ASP.NET Web Service中使用Session 及 Session丢失解决方法 续

原文:http://www.cnblogs.com/lonelyxmas/p/4159087.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!