2011-09-06 160 views
1

我設置了一個登錄控件,以便在我的Web應用程序中使用並且在驗證用戶時出現問題。我在sql server 2008的自己的數據庫中使用另一個站點上的建議創建了成員表。然後我選擇使用表單身份驗證,並在WSAT中創建了兩個用戶,並認爲這可以正常工作。但是它對包括我創建的兩個用戶在內的所有用戶都返回false。爲什麼這是我不確定,如果我要使用SQL數據庫表,我該怎麼做?背後登錄登錄控制表單身份驗證

<authentication mode="Forms"> 
</authentication> 
<authorization> 
    <allow users="boy"/> 
    <allow users="girl"/> 
</authorization> 
<roleManager enabled="true" /> 

代碼:

If Page.IsValid then 
    If username <>"" and password <>"" then 
     If FormsAuthentication.Authenticate(username,passwprd) = False then 
      Return false 
     else 
      response.redirect("~/default.aspx") 
     End If 
    End If 
End If 

回答

2

你需要配置你的web.config使用MembershipProvider

看一看here瞭解更多信息。您是否嘗試使用SqlMembershipProvider

要使用MembershipProvider使用Login用戶控制驗證,或者你可以創建自己的,並調用下面的方法:

if (Membership.ValidateUser(username, password)) 
{ 
    FormsAuthentication.SetAuthCookie(userName, createPersistentCookie); 
    FormsAuthentication.RedirectFromLoginPage(userName, createPersistentCookie); 
} 
+0

是......一個問題。添加成員資格提供程序代碼並添加新用戶後,我看到用戶添加到SQL數據庫中的用戶表。但用戶仍然拒絕訪問。如果需要formauthentication.authenticate() – vbNewbie

+0

更新,請使用 – TheCodeKing

+0

示例更新,謝謝!現在工作 – vbNewbie