2013-05-27 56 views
0

我已經設置了驗證基於我從MCTS自控進度培訓工具包MCTS考試70-562理解下面的表格,但它不驗證...窗體身份驗證不驗證

<authentication mode="Forms"> 
     <forms name="ortund" loginUrl="~/Login.aspx" timeout="30" slidingExpiration="true" /> 
    </authentication> 
</system.web> 

<location path="Members"> 
    <system.web> 
     <authorization> 
      <deny users="?" /> 
     </authorization> 
    </system.web> 
</location> 

基本上它需要允許未經身份驗證的用戶訪問網站的所有區域,除了~/Members/以及其中的所有文件和文件夾。

目前它所做的一切只是重定向回登錄頁面...有沒有我在這裏失蹤的概念?我不明白我做錯了什麼。

下面是登錄代碼:

Protected Sub lnkLogin_Click(sender As Object, e As System.EventArgs) Handles lnkLogin.Click 
    Dim db As New Database 

    ' gets data from the database with the supplied credentials 
    ' if true, the user exists, proceed to log in 
    If db.Login(txtEmail.Text, txtPassword.Text, "ortund") Then 
     FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, True) 

     If Not String.IsNullOrEmpty(Request.Params("ReturnUrl")) Then 
      Response.Redirect(Request.Params("ReturnUrl")) 
     Else 
      Response.Redirect("~/Members/Default.aspx") 
      'Response.Redirect("~/AboutUs.aspx") 
     End If 
    Else 
     lblerr.Text = "Invalid username or password" 
    End If 
End Sub 

而且在Page_Load會員/ Default.aspx的:

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load 
    If Not IsPostBack Then 
     If Context.User.Identity.IsAuthenticated Then 
      loadUserPage() 
     End If 
    End If 
End Sub 
+0

據我的理解,這應該工作,允許30分鐘的超時時間重置,當用戶執行操作... – Ortund

回答

0

Aaaaand全都在震耳欲聾的甜食2狂攬小時打完,IRC, Facebook和Skype ...下面是我修復這個問題的方法:

我創建了一個測試應用程序,以確保我有正確的概念。該測試僅在以上方面有所不同,因爲它使用web.config文件中指定的憑據作爲登錄名,而實際項目會在數據庫中查詢用戶憑據。

您可以下載我的測試代碼here(它使用.NET 4,但您也可以將web.config文件中的相同身份驗證元素應用到較早的框架中)。

因爲這個測試案例的工作原理,我可以確定問題不在代碼中,這意味着它是一個設置問題。

解決方案
在這種情況下的修復很簡單。我從IIS中刪除了虛擬應用程序,並用.NET 4.0 Classic AppPool重新創建它。