C# 在system.webserver中添加模块后,页面无法正确显示
我正在尝试实现一个自定义http安全模块,该模块使用站点地图中的角色来控制对页面的访问,而不必将其全部存储在web.config中。本文如下: 我已将其更新为新版本的IIS,改为在system.webServer中添加模块C# 在system.webserver中添加模块后,页面无法正确显示,c#,forms-authentication,sitemap,httpmodule,C#,Forms Authentication,Sitemap,Httpmodule,我正在尝试实现一个自定义http安全模块,该模块使用站点地图中的角色来控制对页面的访问,而不必将其全部存储在web.config中。本文如下: 我已将其更新为新版本的IIS,改为在system.webServer中添加模块 <system.webServer> <modules> <add name="SecurityHttpModule" type="DINO.SecurityHttpModule"/> </modu
<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)
我想我只是缺少了在添加自定义模块时需要做的其他事情,但我还没有找到任何有关此问题的参考资料。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;
}
该安全模块正在将css请求重定向到登录页面。如果你解决了这个问题,你就会解决你的问题。您可能应该为特定资源文件夹或特定请求匿名页面的模块添加异常。我建议查看模块配置文档