ASP.NET Forms Authentication prevents loading javascript on Login.aspx

独自空忆成欢 提交于 2019-12-29 06:24:08

问题


I am experiencing problems with Forms Authentication. When I try to load my Login.aspx page neither javascript nor stylesheets do not load. Here is part of my web.config file

        <authentication mode="Forms">
        <forms loginUrl="Login.aspx"
               timeout="30"
               name=".ASPXAUTH"
               path="/"
               requireSSL="false"
               slidingExpiration="true"
               defaultUrl="Main.aspx"
               cookieless="UseDeviceProfile" />
    </authentication>

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

Help me, please, to understand what's happening.


回答1:


You need to add exceptions to those directories or files in your web.config, underneath the <configuration> element.

<configuration>
  <system.web>
     ...
  </system.web>

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



回答2:


Put in Global.asax

Public Sub FormsAuthentication_OnAuthenticate(ByVal sender As Object, ByVal args As FormsAuthenticationEventArgs)
    If args.Context.Request.Path.EndsWith("js") Or args.Context.Request.Path.EndsWith("css") Then
        Dim ObjUser As WindowsIdentity = args.Context.Request.LogonUserIdentity
        Dim ObjPrincipal As WindowsPrincipal = New WindowsPrincipal(ObjUser)
        args.User = ObjPrincipal
    End If
End Sub


来源:https://stackoverflow.com/questions/3686613/asp-net-forms-authentication-prevents-loading-javascript-on-login-aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!