Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deny access to unauthorized user in ASP.NET 4.5 WebApp cause JavaScript error on Login form

Tags:

c#

asp.net

When I add following code in web.config to prevent unauthorized user to access ASP.NET WebApp

<authorization>
      <deny users="?"/>
      <allow users="*"/>
</authorization>

I get following error when loading Login.aspx form

In Internet Explorer 11

JavaScript critical error at line 2, column 1 in http://localhost:2968/Account/Login.aspx?ReturnUrl=/bundles/WebFormsJs?v=q9E9g87bUDaS624mcBuZsBaM8xn2E5zd-f4FCdIk2cA1&v=q9E9g87bUDaS624mcBuZsBaM8xn2E5zd-f4FCdIk2cA1

SCRIPT1002: Syntax error

And in Google Chrome

Uncaught SyntaxError: Unexpected token < http://localhost:2968/Account/Login.aspx?ReturnUrl=%2fbundles%2fWebFormsJs%3fv%3dq9E9g87bUDaS624mcBuZsBaM8xn2E5zd-f4FCdIk2cA1&v=q9E9g87bUDaS624mcBuZsBaM8xn2E5zd-f4FCdIk2cA1

like image 613
Sloba Avatar asked Sep 05 '13 07:09

Sloba


1 Answers

You need to add location directives also to allow access to your Scripts and Content folder (JS and CSS) for unauthorized users:

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

Also, as you're using bundles, add the bundles folder too:

<location path="Bundles">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>
like image 90
mattytommo Avatar answered Nov 06 '22 10:11

mattytommo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!