ASP.NET Session State
I'm getting a strange exception in ASP.NET web app relating to the session state. NOTE: The code was produced by a 3rd party....
Basically I'm getting an HttpException with a description of:
Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the \\ section in the application configuration.
The code where the failure occurs looks like so:
public class ExtendedWebPage : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (Context.Session != null)
{
if (Session.IsNewSession || Session["UserID"] == null) <--- Errors Here
{
I'm getting the exception on the 开发者_高级运维test of the if statement, however when I interrogate Context.Session its fine. Up to this point the browser has passed through a Login page which was fine and setup some Session variables which I can see Context.Session, however this.Session is throwing the exeption.
Any ideas?
Thanks,
Philip
Have you checked that Session hasn't been disabled for that page in the @Page
directive in the aspx markup? Further info here.
Finally resolved the issue by renaming the Page and class in the code behind. Creating a new page, copy and pasting the markup into the ASPX and the body of the renamed class into the body of the new class. The code now executes beyond the point where it used to fail.
There's 3 hours I'm not going to get back... :-S
精彩评论