HTTP module: request unavailable

I am creating an http module where I want to check if a request comes from an authenticated user and is redirected to the login page if it is not.

I registered the module in the web.config file, and I have the following code that throws an exception:

public class IsAuthModule : IHttpModule { public void Dispose() { } public void Init(HttpApplication TheApp) { var TheRequest = TheApp.Request; } } 

He throws an exception stating that "Request is not available in this context"

What am I doing wrong?

+4
source share
1 answer

At the Init stage, you have no request. You must subscribe to the event to start the request:

 public void Init(HttpApplication TheApp) { TheApp.BeginRequest += Application_BeginRequest; // End Request handler //application.EndRequest += Application_EndRequest; } private void Application_BeginRequest(Object source, EventArgs e) { // do something } 
+5
source

All Articles