Session access in MasterPage load event after UrlRewrite

Situation:

  • In Web.Config, we included CustomErrors with redirectMode="ResponseRewrite".
  • In Page_Loadour MasterPage we get access to the property Session Page.

Problem:

If an error occurs on any page, the user is redirected (via Rewrite) to the Error.aspx page. There, at Page_Load from MasterPage, we access the session and get an HttpException telling us to enable the SessionState. But we have SessionState enabled, definitely.

Question:

How can we access the session after UrlRewrite in the Page_Load event of our MasterPage?

+3
source share
2

:

if( HttpContext.Current.Session != null )
{
    //Access Session here...
}

, , , ErrorPage.

, HttpContext.Current.Session HttpException, Page.Session .

+1

...

HttpContext.Session null, redirectMode = ResponseRewrite

...

, , , redirectMode - Global.asax Application_Error, , . " " , :

if(Context.IsCustomErrorEnabled)
{
Server.Transfer("~/Error.aspx");
}

Error.aspx Page_Load, .

+1

Source: https://habr.com/ru/post/1754787/


All Articles