使用ASP.NET表单身份验证,如何在登录屏幕上显示图像?

9
我正在为一个小型ASP.NET(3.5,C#)应用程序做简单的表单身份验证,并在web.config中设置我的用户名和密码。
我想应用默认样式表并包含头部图形(在每个其他页面上都包含),但图形和样式表不会应用,可能是因为匿名用户无权访问这两个文件。有没有什么简单的方法让我添加它们或者其他方法使图像出现在页面上?
这是web.config的相关部分:
<authentication mode="Forms">
  <forms name=".ASPXFORMSAUTH" 
    path="/" 
    loginUrl="login.aspx" 
    protection="All" timeout="30">

    <credentials passwordFormat="SHA1">
      <user
          name="testuser"
          password="hashgoeshere"/>
    </credentials>
  </forms>
</authentication>
<authorization>
  <deny users="?" />
</authorization>   

样式表位于: /stylesheet.css 图片位于: /img/logoimage.png
谢谢。希望这个网站能让我感到开心,因为它有望让Experts Exchange和他们的糟糕付费墙消失!

提示关于付费墙的问题...使用谷歌缓存结果获取您要查找的内容。 - Gavin Miller
6
或者,只需使用 Stack Overflow,让 Experts Exchange 慢慢痛苦地死去。 - danieltalsky
1个回答

19

你可以使用特定于位置的规则在Web.Config中添加异常(在System.Web部分之后添加这些规则):

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

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

2
我想指出,位置路径不能以 / 结尾,否则会生成错误。除此之外,这正是我所寻找的!谢谢 :) - Baxter

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接