开发者

Sharing Session between webservice and asp.net application

开发者 https://www.devze.com 2022-12-28 10:45 出处:网络
I have an asp.net application and webservices (asmx) that reside in the same application but not in the same folder of the aspx files. I aslo have a winform application that uses the webservices. I ha

I have an asp.net application and webservices (asmx) that reside in the same application but not in the same folder of the aspx files. I aslo have a winform application that uses the webservices. I have marked the webservice methods with [WebMethod(EnableSession = true)] but I am not able to share the same session values that are on the application in the webservices. The winform application has access to the sessionID from the application and I am using the following code

Uri uri = new Uri(ServerServiceUrl);
_cookieContainer = new CookieContainer();
_cookieContainer.Add(new Cookie("ASP.NET_SessionId", SessionID, "/", uri.Host));

My question is: Is there something that I am mis开发者_JAVA百科sing or doing wrong that I cannot access the application sessioin from the webservices?


I cannot shed any light as to why you are not able to have the winforms app "hijack" the session - what you are doing looks like it should do exactly what you want.

I wanted only to suggest that you use the application cache (to cache the response from you java service) instead of the user's session store. This has the following advantages: -

  • a) If the cached information is applicable to more than an individual user (e.g. access controlled), then the same cached information can be used for several users and not fetched for each session.
  • b) You have more control over how long things are cached for / when they are scavenged than you get with session data (which just lives for the lifetime of your session and has the danger of growing and growing if you forget to delete old information)
  • c) If you do not manage to get your session hijacking working, you can still access data in the cache from any session.


Have you tried inheriting your webservice class from System.Web.SessionState.IRequiresSessionState ?

It's normally used for http handlers, but webservices seem to use the same marker interface.

0

精彩评论

暂无评论...
验证码 换一张
取 消