2010-09-10 56 views
5

我遇到窗體身份驗證問題。當我嘗試加載我的Login.aspx頁面時,無法加載JavaScript或樣式表。 這裏是我的web.config文件ASP.NET窗體身份驗證可防止在Login.aspx上加載JavaScript

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

幫助我,請理解正在發生的事情的一部分。

+0

我懷疑你不加載javascript和CSS的問題是不相關的窗體身份驗證。 FireBug對這些靜態資源有什麼看法? – 2010-09-10 17:04:42

回答

10

您需要在web.config中的這些目錄或文件的<configuration>元素下添加例外。

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

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

重複這個http://stackoverflow.com/questions/55594/css-not-being-applied-on-non-authenticated-asp-net-page – jon3laze 2010-09-10 17:09:45

+0

它的工作原理。非常感謝 :) – Tror 2010-09-10 17:15:09

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