Custom HttpModule running in integrated IIS7 but not classic mode

I have an application written in asp.net, and I have some classic asp pages integrated into the site. The site uses Windows authentication. Since I cannot manage .asp pages with roles, I wrote my own HttpModule to check if the user has permission to view these pages, otherwise he will be redirected to the "refused" page. The main problem is that the application should run in "classic mode" on IIS7. My module works in integrated mode, but not in classic mode. Is there a reason this code should not work in classic mode? Thanks in advance.

Here is the code for the module, it is quite simple:

public class MyModule: IHttpModule { public void Init(HttpApplication application) { application.PostAuthenticateRequest += new EventHandler(Application_PostAuthenticateRequest); } void Application_PostAuthenticateRequest(object source, EventArgs e) { HttpApplication app = (HttpApplication)source; HttpContext context = ((HttpApplication)source).Context; if (context.Request.RawUrl.Contains("/protected-subfolder/")) { // gets user from windows authentication string currentUser = Convert.ToString(context.User.Identity.Name); if (!isAdmin(currentUser)) { //deny access (context.Response).Redirect(VirtualPathUtility.ToAbsolute("~/AccessDenied.aspx")); } } } public void Dispose(){ } 

Here is the setting in web.config for classic mode (doesn't work):

 <configuration> <system.web> <httpModules> <add name="MyModule" type="MyModule" /> </httpModules> </system.web> </configuration> 

And setting for integrated mode (work):

 <configuration> <system.webServer> <modules> <add name="MyModule" type="MyModule"/> </modules> <validation validateIntegratedModeConfiguration="false" /> </system.webServer> </configuration> 
+6
source share
1 answer

In integrated mode, IIS application pools allow you to use any request URL in ASP.NET ISAPI, however in classic mode you will need a third-party ISAPI or the request will be sent directly to the page.

In the integrated module, the FIRST module is checked before the actual contents of the request.

SO:

  • Integrated mode: http://www.yoursite.com/myfile.html first goes through your http modules and routes configured in http modules and global.asax (your .Url request should have the URL above)

  • Classic mode: http://www.yoursite.com/myfile.html checks if there is a file named myfile.html, and if not, it goes to page 404. IF, again, you have your own URLRewrite module.

Hope this helps you.

+2
source

All Articles