1
votes

I'm using InProc session state and for some odd reason, the session variables are always null when I'm using a page method.

If I do this:

var test = HttpContext.Current.Session["test"];

it's showing nothing when I'm running on a page method but if I continue debugging and open another page, it's showing its expected result. I can't post all the code of the app so where should I start looking?

web.config file looks like this:

  <sessionState mode="InProc"/>

Thanks.

1
well start by explaining in what context you use the code above. Is this in the code-behinde of some page (I guess yes) - did you set some value to "test" before this? - Random Dev
Are you setting that variable before using it? Are you running that web application on a farm? InProc session state doesn't meant to be used on this scenario. - Rubens Farias
The above code sits both in a page method and in 2 different aspx pages code behind. The variable is set to value "testworks?" in the master page. When I debug the aspx pages test holds the variable but when I debug the page method, the variable is null. - frenchie

1 Answers

0
votes

If you are setting "test " in a masterpage it will be null in the webmethod. A webmethod doesn't know anything about masterpages.

 [System.Web.Services.WebMethod(EnableSession=true)]
 public static string Bla(double bla)
 {
     //code here
     var test = HttpContext.Current.Session["test"];

 }