I have two webmethod i have used session variable to exchange the username variable between two webmethods but its displaying null in second webmethod ,can we use cookie as alternate to session to store and retrieve username
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool SubmitList1(string username )
{
Session["User_Name"] = username;
.........
.......
}
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public bool addresslisting( string keyword)
{
string username = Context.Session["User_Name"].ToString();
........
.........
}
Disclaimer: I think that a web service that relies on Session state is just plain WRONG since a web service should be stateless. However:
At http://msdn.microsoft.com/en-us/library/aa480509.aspx you can read about how to use ASP.NET Session in a web service:
All in all: a bad design decision gives you more work than necessary (sorry for rubbing it in).
I think you should redesign you web service so that you either always send username and password in all methods or add a login method that gives the client a token that is sent with each web service request.