2010-11-10 41 views
0

我已經把我的證件在web.config中爲:如何設置登錄控件以比較存儲在web.config中的憑證?

<authentication mode="Forms"> 
     <forms loginUrl="Login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20"> 
     <credentials passwordFormat="MD5"> 
      <user name="Nayeem" password="pwd"></user> 
     </credentials> 
     </forms> 
    </authentication> 
    <authorization> 
     <deny users="?"/> 
    </authorization> 

,並有我的登錄控制爲:

<asp:Login ID="LoginEmployees" runat="server"/> 

我希望我的登錄控制在web.config中給出的憑證進行身份驗證文件

+0

感謝編輯親愛的。其實我不知道你在文本編輯器中爲人們做了什麼標記文本或代碼,你可以告訴 – NayeemKhan 2010-11-10 09:49:55

+0

你可以使用Ctrl + K – pavanred 2010-11-10 09:59:28

回答

0

你能做到這樣,
假設您有登錄控制的所有領域,即用戶名和密碼

if (FormsAuthentication.Authenticate(username, password)) 
{ 
    //you can set cookie 
    FormsAuthentication.SetAuthCookie(username, false); 
    //redirect when user is authenticated 
    FormsAuthentication.RedirectFromLoginPage(username, false); 
} 
else 
{ 
    //invalid login 
} 

還要檢查這個post

希望這有助於
邁拉

+0

非常感謝Myra,它的工作! – NayeemKhan 2010-11-10 10:22:43

1

一個簡單的辦法:

private void LoginEmployees_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e) 
{ 
    if (FormsAuthentication.Authenticate(LoginEmployees.UserName, LoginEmployees.Password)) 
    { 
     // Valid login 
     e.Authenticated = true; 
    } 
    else 
    { 
     // Invalid login 
     e.Authenticated = false; 
    } 
}