2

So on my journey to become better at ASP.NET I've encountered a problem.

I'm working on a login. I added some style to it by adding a CSS file and after some time I made it look a lot better. Thereafter I added ASP authentication forms - which actually works great as well except that if you're not logged in the CSS is not used.

Once I've logged in and received a cookie I can go back to the login page and everything looks nice. But as long as I haven't "logged in" the page looks as if no CSS is used.

How can I fix this?

3 Answers 3

11

You have to allow access to the CSS file:

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

Update to match the path to where you store your CSS.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome this works like a charm. May I ask why location has to be before system.web? and why it's wrapped around most of the other things in the web.config file? and if I may sidetrack my own question what does allow users="*" exactly do? So far I've only written <deny users="?" /> in my Authorization tag :)
2

You need to exclude the CSS folder (and for that matter any other folders) from the authorization using location in the web.config.

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

Comments

1

Move your CSS folder out of the protected area - put it under your root, and it should work.

The CSS for the protected files can reside in the (non-protected) anonymous access, root folder. The CSS for your protected files does not have to be in a protected folder, but if you must do that, then amit_g's solution should work for that scenario :)

2 Comments

What do you exactly mean by that?
The CSS for the protected files can reside in the (non-protected) anonymous access, root folder. The CSS for your protected files does not have to be in a protected folder, but if you must do that, then amit_g's solution should work for that scenario:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.