2012-08-29 128 views
0

我試圖將表單身份驗證配置爲密碼保護文件夾。即使證書是正確的,當前也不會登錄任何用戶。表單身份驗證不能以正確的憑據登錄

這裏是我的代碼...

Web配置:

<authentication mode="Forms"> 
    <forms name=".ASPXAUTH" loginUrl="login.aspx" protection="All" timeout="999999"> 
    <credentials passwordFormat="MD5"> 
     <user name="admin" password="passwordhashhere" /> 
    </credentials> 
    </forms> 
</authentication> 
<authorization> 
    <allow users="?" /> 
</authorization> 

那麼最後的System.Web外:

<location path="Admin"> 
    <system.web> 
    <authorization> 
     <allow users="admin" /> 
     <deny users="*" /> 
    </authorization> 
    </system.web> 
</location> 

然後在我的aspx:

<div class="user"> 
    <p>Username:</p> 
    <br /> 
    <asp:TextBox ID="TextBoxUser" runat="server"></asp:TextBox> 
</div> 

<div class="pass"> 
    <p>Password:</p> 
    <br /> 
    <asp:TextBox ID="TextBoxPass" runat="server" TextMode="Password"></asp:TextBox> 
</div> 

<div class="login"> 
    <asp:Button ID="ButtonLogin" runat="server" Text="Log In" /> 
    <asp:Label ID="LabelError" runat="server" Text=""></asp:Label> 
</div> 

然後在我的codebehin d:

Protected Sub ButtonLogin_Click(sender As Object, e As System.EventArgs) Handles ButtonLogin.Click 
    If Membership.ValidateUser(TextBoxUser.Text, TextBoxPass.Text) Then 
     If Request.QueryString("ReturnUrl") IsNot Nothing Then 
      FormsAuthentication.RedirectFromLoginPage(TextBoxUser.Text, False) 
     Else 
      FormsAuthentication.SetAuthCookie(TextBoxUser.Text, False) 
     End If 
    Else 
     LabelError.Text = "Invalid UserID and Password" 
    End If 
End Sub 

回答

1

嘗試

<deny users="?" /> 

,而不是在你的第二個代碼塊<deny users="*" /> ...

<allow users="*" /> 

,而不是<allow users="?" />在第一個代碼塊或其不需要..