Click here to Skip to main content
13,252,183 members (56,177 online)
Rate this:
Please Sign up or sign in to vote.
In my web service I need to get one value from session variable. In the constructor of my web service I am getting this value like

constructor()  // constructor of web service
  Person p = (Person)Session["xyz"];
  string name = p.Name;
  string Address = p.Address

my java script is like bellow

function CallWebservice()

It works perfectly fine but some time i got the session as null, i have the session state in web.config which has default time out as 60 minutes.

but before 60 minutes(not all the time) the session is getting null, this things happens only when i am calling the webservice from java script
Posted 13-Feb-13 3:14am
Updated 13-Feb-13 3:35am
ryanb31 13-Feb-13 9:42am
Do you have [WebMethod(EnableSession = true)] on your webmethod?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Im agreed with ryanb31 answer.
First you have to enable the session in your web service.
you can do that by adding following line to your web service
[WebMethod(EnableSession = true)][^][^]

and avoid the session time out, you can create a non functional web service and keep calling to it using the javascript setInterval method.
        public void KeepAlive()
            //do nothing

//to keep the session alive
  //call KeepAlive web service 
}, 60000);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100