How to use Session in Web Service web method in ASP.Net

rohit.sood8
 
on Sep 07, 2014 11:21 PM
14369 Views

sir i am following one of your links:

http://www.aspforums.net/Threads/184700/Assign-JavaScript-variable-value-to-ASPNet-Session-variable-using-JQuery-AJAX/

 

But this concept is not working in master page, i have kept the script in the master page and calling the function in the content page link button OnClientClick. Function gets called, but its not calling the webservice method, i have just replaced one line:

Kindly suggest, bit urgent.

url: "CS.aspx/SetSession",

with

url: 'WebService.asmx/SetSession',

Download FREE API for Word, Excel and PDF in ASP.Net: Download
rohit.sood8
 
on Sep 07, 2014 11:59 PM

i got it working, earlier it was like this:

[WebMethod]
public static void SetSession(string value)
{
    HttpContext.Current.Session["Value"] = value;
}

I removed static keyword and set EnableSession = true...

[WebMethod(EnableSession = true)]
public void SetSession(string value)
{
   HttpContext.Current.Session["Value"] = value;
}

Thanks
Rohit