views:

54

answers:

1

i have converted a web application project from 2003 to 2005.everything works fine in 2003,but the converted web application project in 2005 has some problem, problem is in session values,initially the session value works fine(for the first time),but if the page is loaded for the second time the session value becomes empty.

in first page session value is set and in second page the session value is received then i click the button the page will reloaded now the session value is empty..

please get me some answers or links to refer.

A: 

Check if your application doesn't alter anything in the folder structure, like creating new files or folders. That often causes the application to be reset, which causes the loss of the Session information. Especially some special folders and files, like the App_Code folder and the Web.Config, cause an immediate application reset when modified.

If this is not the case, then it might be a code logic problem. Try to refactor the session variable's read/writes into using a property:

private string MySessionVar {
    get { return (string)Session["MySessionVar"]; }
    set { Session["MySessionVar"] = value; }
}

Then add breakpoints to the getter and setter and run your code to check what's causing the session variable to be overwritten. Be sure to check usercontrols if you use them.

Also, if the variable is only used on the current page, you might consider using a Viewstate variable instead.

Prutswonder