我有一个用asp.net编写的应用程序,我在网站中集成了一些传统的经典asp页面 . 该站点使用Windows身份验证 . 因为我无法管理带有角色的.asp页面,所以我编写了一个自定义HttpModule来检查用户是否有权查看这些页面,否则会重定向到“拒绝访问”页面 . 主要问题是应用程序需要在IIS7上以“经典模式”运行 . 我的模块在集成模式下工作,但在经典模式下不工作 . 有没有理由这个代码也不能在经典模式下工作?提前致谢 .
这是模块的代码,它非常简单:
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(){ }
这是经典模式的web.config中的设置(不工作):
<configuration>
<system.web>
<httpModules>
<add name="MyModule" type="MyModule" />
</httpModules>
</system.web>
</configuration>
并且集成模式(工作)的设置:
<configuration>
<system.webServer>
<modules>
<add name="MyModule" type="MyModule"/>
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
</configuration>
1 回答
在集成模式下,IIS应用程序池允许任何请求URL进入ASP.NET ISAPI,但是,在经典模式下,您需要第三方ISAPI,否则请求将直接发送到页面 .
在集成中,模块在实际请求内容之前首先进行检查 .
所以:
集成模式:http://www.yoursite.com/myfile.html首先浏览http模块和http模块和global.asax中配置的路由(你的Request.Url应该有上面的URL)
经典模式:http://www.yoursite.com/myfile.html检查是否确实存在名为myfile.html的文件,如果没有,则进入404页面 . 除此之外,您还有一个自定义URLRewrite模块 .
希望这有助于你 .