ASP.NET表单身份验证阻止在Login.aspx页面加载JavaScript。

5

我遇到了表单身份验证的问题。当我尝试加载我的Login.aspx页面时,既没有JavaScript也没有样式表被加载。 以下是我的web.config文件的一部分:

        <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>

请帮助我理解正在发生的事情。


我怀疑你加载JavaScript和CSS的问题与表单身份验证无关。FireBug对这些静态资源有何说法? - Darin Dimitrov
2个回答

10

您需要在<configuration>元素下方的web.config文件中为那些目录或文件添加异常。

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

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

这是一个与此相似的问题:https://dev59.com/eHVD5IYBdhLWcg3wNIrc。 - jon3laze

0

将其放置在 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接