facebook
facebook

Reputation: 1864

using session state in webservice in ASP.NET

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

Answers (3)

Felipe Sabino
Felipe Sabino

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

Damian
Damian

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

Related Questions