Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 23, 2011 08:49 PM by stevex33
Member
356 Points
337 Posts
Dec 23, 2011 06:14 PM|LINK
Hi,
I've got a class that I'm working with, and when it's run, I want to add something to the session, or access an existing session variable.
However I keep getting a null reference exception.
The class acts a route contraint if that matters:
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { httpContext.Session.Add("pageId","mytestvalue");
but whenever code gets to that point, it crashes.
can anyone help me out please.
I know how to access session variables from within a page, but I didn't think it would be a difference when the place the code is running from isn't a page.
All-Star
112168 Points
18255 Posts
Moderator
Dec 23, 2011 06:21 PM|LINK
Dec 23, 2011 06:26 PM|LINK
thanks, unfortunately I'm still getting the same error, session is null.
Dec 23, 2011 08:49 PM|LINK
I've seen that using "HttpContext.Current.Items" is the correct way to go.
stevex33
Member
356 Points
337 Posts
Trying to access session variables outside of a page?
Dec 23, 2011 06:14 PM|LINK
Hi,
I've got a class that I'm working with, and when it's run, I want to add something to the session, or access an existing session variable.
However I keep getting a null reference exception.
The class acts a route contraint if that matters:
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { httpContext.Session.Add("pageId","mytestvalue");but whenever code gets to that point, it crashes.
can anyone help me out please.
I know how to access session variables from within a page, but I didn't think it would be a difference when the place the code is running from isn't a page.
MetalAsp.Net
All-Star
112168 Points
18255 Posts
Moderator
Re: Trying to access session variables outside of a page?
Dec 23, 2011 06:21 PM|LINK
stevex33
Member
356 Points
337 Posts
Re: Trying to access session variables outside of a page?
Dec 23, 2011 06:26 PM|LINK
thanks, unfortunately I'm still getting the same error, session is null.
stevex33
Member
356 Points
337 Posts
Re: Trying to access session variables outside of a page?
Dec 23, 2011 08:49 PM|LINK
I've seen that using "HttpContext.Current.Items" is the correct way to go.