Thursday, 5 March 2009

FBA Login Page - Images not showing when user is Anonymous

I have been doing a lot of work with FBA and custom membership providers and here is something that is so simple but nearly caught me out.
The Client was happy with the way the login worked but complained that the styling was different from the rest of the site. So one of our designers put together a Simple.Master based on the main master pages styling and a custom CSS.
So we added this to our solution and deployed it to our staging environment.
The login page loaded fine but neither the CSS file nor the images were being pulled through leaving the login page looking worse than before. At first thought I was a little confused as the CSS and the images were stored in a Layouts/{Project Name}/CSS and Images folder and worked fine once a user was logged in. Then I realised exactly where I had gone wrong, The Layouts folder is only accessible to authenticated users, this is not only expected but wanted. So as WSS is based on ASP.Net we can open a path to our CSS and Images folders to allow Anonymous users to see the files and only these files.
We added the following to the Web.Config

<location path="_layouts/{Project}/images">
<system.web>
<authorization>
<allow users="*">
</allow>
</authorization>
</system.web>
<location path="_layouts/{Project}/CSS">
<system.web>
<authorization>
<allow users="*">
</allow>
</authorization>
</system.web>

It would have been possible to place the Images in the Images folder but I prefer to keep all Custom files in the layouts/{Project Name} format as it makes it easier for admins to track the changes our solution has made to their servers.
Also to note there is nothing in these folders that would be need to be protected however there are some files in the layouts/{Project Name} that should only be available to authenticated so we could not just open up the entire Folder.

Any way just something small that helped.

No comments: