【问题标题】:How can you prevent Formsauthentication to block css and images?如何防止 Formsauthentication 阻止 css 和图像?
【发布时间】:2010-06-28 07:30:03
【问题描述】:

我有一个包含图像、css 和 js 文件夹的项目。
我想确保在使用表单验证时不会阻止 css、图像或 js。

我知道您可以使用 web.config 中的 locationtag 执行此操作,但我想知道您是否可以执行此操作?

这就是我现在的做法:

<location path="css">
        <system.web>
            <authorization>
                <allow users="*"/>
            </authorization>
        </system.web>
    </location>
    <location path="images">
        <system.web>
            <authorization>
                <allow users="*"/>
            </authorization>
        </system.web>
    </location>

我正在使用带有 iis 7.0 的 asp.net (c#)。

干杯, M.

【问题讨论】:

标签: asp.net css image forms-authentication


【解决方案1】:

为您的 CSS/images 目录设置文件夹权限,以允许匿名访问。

这是在 web.config 中完成的,而不是文件系统权限。

【讨论】:

  • 是的,我知道这就是我在问题中提到的。但我想知道是否还有其他方法。
【解决方案2】:

good practice 提供静态资源,例如来自无 cookie 域的图像和 css。

【讨论】:

    【解决方案3】:

    我一直在寻找相同的答案,但在我的情况下,默认情况下它允许访问 CSS、图像和 JS 文件。我认为它只需要对 ASPX(等)进行身份验证。

    另外,我正在使用拒绝用户“?”而不是 ”*”

    【讨论】: