C# 如何设置登录控件以比较web.config中存储的凭据?

C# 如何设置登录控件以比较web.config中存储的凭据?,c#,asp.net,C#,Asp.net,我已在web.config中将我的凭据设置为: <authentication mode="Forms"> <forms loginUrl="Login.aspx" name=".ASPNETAUTH" protection="None" path="/" timeout="20"> <credentials passwordFormat="MD5"> <user name="Nayeem" passwor

我已在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文件中提供的凭据进行身份验证

您可以这样做,
假设您拥有所有登录控制区域,即用户名和密码

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
 }
也检查一下这个

希望这有帮助
Myra

一个简单的解决方案:

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; } } 私有void LoginEmployees\u身份验证(对象发送方,System.Web.UI.WebControls.authenticateventargs e) { if(FormsAuthentication.Authenticate(LoginEmployees.UserName,LoginEmployees.Password)) { //有效登录 e、 已验证=真; } 其他的 { //无效登录 e、 认证=假; }
}亲爱的,谢谢你的编辑。事实上,我不知道你们在文本编辑器里做什么来标记文本或代码,你们能告诉我吗