使用web.config目录安全性和无扩展名的URL

时间:2010-02-19 20:43:10

标签: asp.net security authentication web-config authorization

我想使用web.config中内置的内置目录安全功能来限制对父页面的子页面的访问。我的结构如下:

  • 会员
  • 会员/新闻
  • 会员/媒体
  • 会员/影

用户应该能够访问成员父页面,但不能访问子页面。我的问题是,因为我使用无扩展名的URL,web.config认为这是一个目录,所以访问被阻止。有没有办法说只限制子页面的访问?

1 个答案:

答案 0 :(得分:3)

此配置应该可以解决问题。它允许整个网站的匿名访问,除了其他位置 - 他们需要经过身份验证的用户才能工作。

<configuration>
    <system.web>
        <authentication mode="Forms">
            <forms loginUrl="Login" defaultUrl="Members" />
        </authentication>
        <authorization>
            <allow users="?" />
        </authorization>
    </system.web>

    <location path="Members/News">
        <system.web>
            <authorization>
                <deny users="?" />
                <allow users="*" />
            </authorization>
        </system.web>
    </location>

    <location path="Members/Press">
        <system.web>
            <authorization>
                <deny users="?" />
                <allow users="*" />
            </authorization>
        </system.web>
    </location>

    <location path="Members/Movies">
        <system.web>
            <authorization>
                <deny users="?" />
                <allow users="*" />
            </authorization>
        </system.web>
    </location>

</configuration>
相关问题