ChatingCSDN的原贴看了看,翻到了后面第3页,发现了回答。将EnableSession设为True是可以的。
从WebService的SessionID说起    <System.Web.Services.WebMethod(EnableSession:=True)> _

从WebService的SessionID说起        
Return Session.SessionID
从WebService的SessionID说起    
End Function
但是问题远比想的复杂,在本机调试的时候得到的SessionID是固定的,换了一下机器请求一次得到一个不同的SessionID。
尝试着把Web.Config的配置改了一下(将cookieless设置为true)。
从WebService的SessionID说起  <!--  会话状态设置
从WebService的SessionID说起          默认情况下,ASP.NET 使用 Cookie 来标识哪些请求属于特定的会话。
从WebService的SessionID说起          如果 Cookie 不可用,则可以通过将会话标识符添加到 URL 来跟踪会话。
从WebService的SessionID说起         若要禁用 Cookie,请设置 sessionState cookieless="true"。
从WebService的SessionID说起    
-->
从WebService的SessionID说起    
<sessionState 
从WebService的SessionID说起            
mode="InProc"
从WebService的SessionID说起            stateConnectionString
="tcpip=127.0.0.1:42424"
从WebService的SessionID说起        sqlConnectionString
="data source=127.0.0.1;Trusted_Connection=yes"
从WebService的SessionID说起            cookieless
="false" 
从WebService的SessionID说起            timeout
="20" 
从WebService的SessionID说起    
/>
问题同样没有解决。
最后我曲线救国完成了功能,但也已经不是Session了。
在数据库里新建一个表,保存Session信息。用户登陆的时候分配一个会话ID,放在表里。在每个WebMethod中都加一个参数,用来传递这个ID,然后再数据库里查找需要的东西。最后在用户注销的时候再把数据库里相应行删除。 
enjoyit-zwg的解决方案:
每次请求的SessionId都是不同的,但是可以通过设置Web服务代理的CookieContainer属性来使多次调用在同一个SessionlD。

相关文章:

  • 2021-12-23
  • 2021-11-18
  • 2022-12-23
  • 2022-01-26
  • 2022-12-23
猜你喜欢
  • 2021-07-03
  • 2021-08-12
  • 2021-09-29
  • 2021-11-06
  • 2022-02-22
  • 2021-08-18
  • 2021-07-15
相关资源
相似解决方案