asp.net-mvcforms-authenticationhttp-status-code-302

Forms auth redirecting css/script includes to the login page with HTTP 302


I have some includes on a login page, a css file and a js file.

<link rel="stylesheet" type="text/css" href="../../ext/resources/css/ext-all.css" />
<script type="text/javascript" src="../../ext/bootstrap.js"></script>

the requests the browser makes for these get the 302 response. Forms Auth is seeing the request as unauthorized and redirecting them to the login page. It doesn't realise that the requests are coming from the login page in the first place.

GET http://localhost:50880/ext/resources/css/ext-all.css HTTP/1.1

HTTP/1.1 302 Found
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/Account/LogOn?ReturnUrl=%2fext%2fresources%2fcss%2fext-all.css">here</a>.</h2>
</body></html>

I thought perhaps setting the permissions of the includes folder (ext) to everyone might help.


Solution

  • You need to exclude the css files and images from getting authenticated as following in the configuration file. Using the location tag you can exclude a single file or a directory.

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