小编lem*_*lem的帖子

自定义HttpModule在IIS7中集成,但不是经典模式

我有一个用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(){ }
Run Code Online (Sandbox Code Playgroud)

这是经典模式的web.config中的设置(不工作):

<configuration>
    <system.web>
        <httpModules>
            <add name="MyModule" type="MyModule" />
        </httpModules>
    </system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)

并且集成模式(工作)的设置:

<configuration>
    <system.webServer>
        <modules>
            <add name="MyModule" type="MyModule"/>
        </modules>
        <validation validateIntegratedModeConfiguration="false" />
    </system.webServer> …
Run Code Online (Sandbox Code Playgroud)

.net asp.net iis-7 httpmodule

6
推荐指数
1
解决办法
3956
查看次数

标签 统计

.net ×1

asp.net ×1

httpmodule ×1

iis-7 ×1