Ever tried accessing session variables in Web Service methods? It won't work unless you add a little property in the WebMethod header of the functions.
For example, the basic hello world:
[WebMethod(EnableSession=true)]
public void HelloWorld()
{
...
}
Just add the statement EnableSession=true and you'll be able to access session variables found normally in aspx pages like the following sample.
string userid = Session["userid"].ToString();
Saturday, April 17, 2010
ASP.NET Enable Session in Web Service Methods
Labels:
asp.net,
c#,
enablesession,
web method,
web services
Subscribe to:
Post Comments (Atom)
Its nothing like that. I tried without using that, It worked.
ReplyDelete//Page Load
Session["sid"] = "123";
//Web Service Method
var s = Session["sid"]; //s = "123"
Awesome work.Just wanted to drop a comment and say I am new to your blog and really like what I am reading.Thanks for the share
ReplyDeleteHey keep posting such good and meaningful articles.
ReplyDeleteVery informative, keep posting such good articles, it really helps to know about things.
ReplyDeleteVery interesting blog. A lot of blogs I see these days don't really provide anything that attract others, but I'm most definitely interested in this one. Just thought that I would post and let you know.
ReplyDeleteVery great post. I simply stumbled upon your blog and wanted to say that I have really enjoyed browsing your weblog posts. After all I’ll be subscribing on your feed and I am hoping you write again very soon!
ReplyDeleteHey keep posting such good and meaningful articles.
ReplyDeleteWhat you're saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I'm sure you'll reach so many people with what you've got to say.
ReplyDeleteIt was very useful for me. Keep sharing such ideas in the future as well. This was actually what I was looking for, and I am glad to came here! Thanks for sharing the such information with us.
ReplyDelete