2

Please see below code

public class URLRewriter : IHttpModule {

    public void Dispose() {

    }
    public void Init( HttpApplication context ) {
        context.BeginRequest += new EventHandler( context_BeginRequest );
    }

    void context_BeginRequest( object sender, EventArgs e ) {
                //code to make custom 
                 URLhttpApplication.Context.Server.Transfer( CustomPath );

        }
}

Here i am using IHttpModule for making custom URL redirection. But it showing error while setting session in destination page.

ERROR LINE Code :

HttpContext.Current.Session[USERADMIN] == null

ERROR Message:

System.NullReferenceException: Object reference not set to an instance of an object.

Manu
  • 89
  • 1
  • 9
  • Check this other post: [1]: http://stackoverflow.com/questions/276355/can-i-access-session-state-from-an-httpmodule – Rui Lima Aug 22 '13 at 13:24

1 Answers1

2

You are asking for Session state in BeginRequest, which is before the session state is available in the application's lifecycle. At minimum, you can't use session state until the AcquireRequestState event.

Change your Init to handle the AcquireRequestState instead of BeginRequest.

vcsjones
  • 138,677
  • 31
  • 291
  • 286