在 IIS7 静态内容集成模式中使用角色进行 ASP.NET 身份验证
我正在试验IIS7中静态内容的集成身份验证模式。 我按照本文中的说明进行操作: https://web.archive.org/web/20210612113955/https://aspnet.4guysfromrolla.com/articles/122408-1.aspx 如果我通过登录状态允许/拒绝访问(如文章中所示),则工作正常。 不过,我想根据角色允许/拒绝访问(使用内置角色提供程序的 ASP.NET)。 当我在 web.config 中为“管理员”角色设置允许规则并为所有其他用户设置拒绝规则时,即使我以管理员身份登录,也无法访问静态文件。 同一文件夹包含非静态内容(aspx 页面),可以根据角色提供程序信息很好地访问这些内容。
有任何想法吗?
I am experimenting with the integrated authentication mode for static content in IIS7. I followed the instructions in this article: https://web.archive.org/web/20210612113955/https://aspnet.4guysfromrolla.com/articles/122408-1.aspx
It is working fine if I allow/deny access by login status (like in the article). However I want to allow/deny access based on roles (using the ASP.NET built in Roles Provider). When I put an allow rule for the role "Admin" in the web.config and deny rule for all other users I am not able to access the static files even when I login as an admin. The same folder contains non-static content (aspx pages) that are accessed just fine based on the Role Provider information.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将以下内容添加到您的
中:
块:RoleManager
位是关键,它没有包含在我能找到的任何在线示例中。 否则,用户的角色成员身份不会针对静态内容进行初始化,因此基于角色的授权将始终失败。(免责声明:根据我对 IIS 的有限了解,我自己将其拼凑在一起,但它似乎有效。)
编辑(回应您的评论):抱歉,我不太了解RoleManager 如何依赖其他模块。 您可以通过查看
c:\Windows\System32\inetsrv\config\applicationHost.config
(至少在我的 Windows Vista 计算机上是这样)来查看默认的 IIS 配置,以查看其中的顺序加载模块(注意使用 managedHandler默认情况下将 RoleManager 限制为非静态内容),MSDN 涵盖 RoleManagerModule 以及 System.Web 中的其余模块.Security 命名空间,因此您可能可以在那里找到您需要的内容。Try adding the following to your
<system.webServer> <modules>
block:The
RoleManager
bit is key, and it's not included in any of the online examples that I could find. Without that, the user's role membership isn't initialized for static content, so role-based authorization will always fail.(Disclaimer: I've pieced this together myself based on my limited understanding of IIS, but it seems to work.)
Edit (in response to your comment): Sorry, I don't know much about how RoleManager depends on other modules. You can view the default IIS configuration by looking at
c:\Windows\System32\inetsrv\config\applicationHost.config
(at least, that's the past on my Windows Vista machine) to see the order in which modules are loaded (note the use of managedHandler by default to restrict RoleManager to non-static content), and MSDN covers RoleManagerModule along with the rest of the modules in the System.Web.Security namespace, so you could probably find what you need there.我想说最可能的罪魁祸首是静态文件没有由 ASP.NET 处理,而是由 IIS 处理。
如果添加通配符脚本映射是否有效?
I would say the most likely culprit is that the static files are not being processed by ASP.NET but being left up to IIS.
Does it work if you add a wildcard script mapping?