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。

 

posted on 2010-07-24 22:37  Ferry  阅读(2071)  评论(0编辑  收藏  举报

导航