How to get Session Parameters in an ASP.NET ASMX service.

By admin. Filed in ASP.NET, Delphi Prism 2010, Microsoft Visual Studio, Programming  |   
Tags: , , , ,
TOP del.icio.us digg

Session parameters get used a lot in ASP.NET pages and they work pretty well, but when you try to use them in an ASMX web service, you get errors.  So, how do you get the session parameters?

It turns out that it is really simple.  Just add “EnableSession = true” to your WebMethod and it all works as expected.  For example:

[WebMethod (Description="Get a list of RMU GPS positions as JSON for the current custId.",
    EnableSession = true)]
public string GetSomeData()
{
    string  custId = "0";
    try
    {
        custId = Session["CustId"].ToString();
        return(GetSomeDataFromClientId( CustId );
    }
    catch (Exception ex)
    {
        handleException(ex, "GetGpsRmuCustListJSON");
        return(some failure message...);
    }
}
Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • Diigo
  • MisterWong

Leave a Reply