views:

581

answers:

2

I have just noticed a problem accessing a CSS file using forms authentication from an ASP.NET application.

Until I have logged in, then any styles I have set in my login page are not used, as IIS seems to be preventing the login page from accessing this file.

Is there an easy solution for this?

+4  A: 

Place the css file in a publicly accessible folder. This will require a change in your web.config that will look something like this:

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

Granted, this shouldn't be how you setup the permissions in the first place. The css folder ought always to be publicly accessible.

Gavin Miller
Would you mind expanding on how I should set up permissions in the first place?
Patrick McDonald
It's going to vary, for example you could make everything publicly available and then check permissions before serving the file up. Or you could make everything public except for files under the *private* folder. There's any number of configurations, typically all of which will have the javascript, images, css publicly available.
Gavin Miller
A: 

My CSS didn't display in the login page as well.

I noticed that Anonymous Access was using the IUSR account not the IIS_IUSRS account so I just added IUSR to the website folder and everything got back to normal.

Sigurbjörn