Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ASP.NET Forms Authentication, how do I get an image to appear on the login screen?

I am doing simple forms authentication for a small ASP.NET (3.5, C#) application and setting up my usernames and passwords in the web.config.

I would like to apply the default stylesheet and include the header graphic (included on every other page) but the graphic and stylesheet won't apply, presumably because the anonymous user doesn't have access to those two files. Is there some easy way for me to add them or some other way to make the image appear on the page?

Here is the relevent section of the 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>   

The stylesheet is at: /stylesheet.css and the image is at: /img/logoimage.png

Thanks. This site makes me happy because hopefully it will make Experts Exchange and their lame paywall DIE!

like image 903
danieltalsky Avatar asked Jan 27 '09 22:01

danieltalsky


1 Answers

You can add exceptions in your Web.Config using location-specific rules (add these after the System.Web section):

<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>
like image 82
Chris Van Opstal Avatar answered Sep 21 '22 15:09

Chris Van Opstal