Session is null in WebMethod

Last post 04-06-2009 1:48 PM by jeff@zina.com. 1 replies.

Sort Posts:

  • Session is null in WebMethod

    03-13-2009, 2:55 PM
    • Member
      21 point Member
    • Tom_Regan
    • Member since 08-10-2004, 12:11 PM
    • Posts 38

    I have an *.asmx page running inside a sharepoint public web site. I created the page so that I can call make WebMethod calls from javascript using asp.net AJAX. I followed the instructions in http://msdn.microsoft.com/hi-in/library/ms464040.aspx, which basically contains these steps:

    1. Create a separate web application with the *.asmx page.
    2. Build it and put the *.dll in the GAC.
    3. Run disco on the .asmx page, and copy the .asmx, .disco, and .wsdl files into the ISAPI folder in the 12 hive of Sharepoint. 
    4. Edit the asmx file to point to the dll in the GAC instead of the code behind.

    It works--I can hit the webpage in the sharepoint site and call my webmethod in javascript.  The only problem is that Session is null inside the web method.  I need Session to pass to various middle-tier components that read from HttpContext.Current.Session.  When session is null these components blow up.

     I enabled session in the WebMethod attribute [WebMethod(true)], and session is enabled in the web.config.

     Am I barking up the wrong tree?  Is there any way to pass the Sharepoint web site session into my WebMethod?

    When I debug I can see that the sessionid cookie is being passed correctly from Sharepoint to my WebMethod.  For some reason my WebMethod is failing to instantiate the Session.

    Tom Regan
  • Re: Session is null in WebMethod

    04-06-2009, 1:48 PM
    • All-Star
      77,739 point All-Star
    • jeff@zina.com
    • Member since 09-26-2003, 10:43 AM
    • Naples, FL, USA
    • Posts 10,566
    • Moderator
      TrustedFriends-MVPs
    Blatant Self Promotion: ASP.NET 3.5 CMS Development
Page 1 of 1 (2 items)