views:

1701

answers:

3

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!

+12  A: 

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>
Chris Pebble
Thank you. You rule.
danieltalsky
A: 

good work buddy this actually worked compare what, other thing i found, pees remember to make a tag for each sub level until you get to the file.

SantaX
A: 

Wonderfull! it really works!

so... just to conclude, if I have an authentication, it blocks everything unless I have this exception in the web.config file.

Regards.

tester