I have an application that is written in asp.net and I have some legacy classic asp pages integrated into the site. The site uses Windows authentication. Because I cannot manage .asp pages with roles, I've written a custom HttpModule to check if a user has permissions to view those pages, otherwise it redirects to an "access denied" page. The main issue is that the application needs to run in "classic mode" on IIS7. My module works in integrated mode, but not in classic mode. Is there any reason this code shouldn't work in classic mode as well? Thanks in advance.
Here is the code for the module, it's pretty 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 (not working):
<configuration>
<system.web>
<httpModules>
<add name="MyModule" type="MyModule" />
</httpModules>
</system.web>
</configuration>
And the setting for integrated mode (working):
<configuration>
<system.webServer>
<modules>
<add name="MyModule" type="MyModule"/>
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
</configuration>
<validation validateIntegratedModeConfiguration="false" />
I get the same behavior as before. I suspect my issue has something to do with this: markcz.wordpress.com/2011/12/31/… – lem