Reputation: 1864
On login, i am saving username into Session["username"]
. On next page, I am making a web service call. In web service, I want to access this session.
How to do this?
I've tried even set EnableSession
to true of webmethod. But, still on executing Session["username"]
, instance set to null exception is show.
Please help.
Upvotes: 1
Views: 5628
Reputation: 18215
You should never do that.
A Web service is a method of communication between two electronic devices over a network. This 2 devices do not share sessions or any other server information besides those expilicitly defined by the web service signature.
You have to remember that any device can access you web service and it this access should not depends on the language the it is using.
As a result, you should add all the information you want to share via in the response you give.
Upvotes: 5
Reputation: 511
Is that web service exist in the same application? How do you perform your login, do you use Membership provider to do that?
Maybe you just can get a username from
HttpContext.Current.User.Identity.Name
the IPrincipal object corresponding with your logged in user?
Upvotes: 1
Reputation: 11311
You can find at http://msdn.microsoft.com/en-us/library/aa480509.aspx
http://www.codeproject.com/articles/35119/Using-Session-State-in-a-Web-Service.aspx
Upvotes: 0