【问题标题】:Pages don't display correctly after adding module in system.webserver在 system.webserver 中添加模块后页面无法正确显示
【发布时间】:2015-11-10 20:19:39
【问题描述】:

我正在尝试实现一个自定义 http 安全模块,该模块使用站点地图中的角色来控制对页面的访问(而不必将其全部存储在 web.config 中)。以下文章:http://www.codeproject.com/Articles/8728/Extending-ASP-NET-security

我已经为较新版本的 IIS 更新了它,而是在 system.webServer 中添加了模块

<system.webServer>
   <modules>
      <add name="SecurityHttpModule" type="DINO.SecurityHttpModule"/>      
   </modules>
</system.webServer>

在这方面似乎一切正常,但页面不再正确呈现。如果我在 Chrome 中查看控制台,我会看到类似

的错误
Resource interpreted as Stylesheet (or Script) but transferred with MIME type test/html: "http://localhost:57855/login" 
    and
Uncaught SyntaxError: Unexpected token <  (about the <!DOCTYPE html> at the top of the page)

我想我只是在添加自定义模块时遗漏了其他一些我需要做的事情,但我还没有找到任何关于这个问题的参考。

【问题讨论】:

  • 该安全模块正在将该 CSS 请求重定向到登录页面。如果你解决了这个问题,你就会解决你的问题。您可能应该为特定资源文件夹或特定请求(匿名页面)向模块添加例外。我建议检查模块配置文档

标签: c# forms-authentication sitemap httpmodule


【解决方案1】:

Oguz Ozgul 的评论是正确的。为了解决这个问题,我添加了一个我想要验证权限的扩展列表,然后我将其作为身份验证请求方法的第一部分进行检查。

private static readonly List<string> extensionsToValidate = new List<string>(new string[] { ".aspx", "" });

private void AuthenticateRequest(Object sender, EventArgs e)
{
    //Ignore specified extensions from redirection
    string CurrentExt = Path.GetExtension(HttpContext.Current.Request.Url.LocalPath);
    if (extensionsToValidate.Contains(CurrentExt))
    {
        //do all security check work here
    }
    else return;
}

【讨论】:

    猜你喜欢
    • 2016-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-30
    • 2011-03-31
    • 2018-03-19
    • 2020-07-12
    • 1970-01-01
    相关资源
    最近更新 更多