6

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

4

1 回答 1

9

您还需要添加位置指令以允许未经授权的用户访问您的脚本和内容文件夹(JS 和 CSS):

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

此外,当您使用捆绑包时,也请添加捆绑包文件夹:

<location path="Bundles">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>
于 2013-09-05T07:53:17.957 回答