简体   繁体   English

如何在ASP.NET中验证用户

[英]How to Authenticate user in ASP.NET

I have SQL Database with all my users. 我和所有用户都有SQL数据库。 I want to use default login page of ASP.NET 4 WebSite Template. 我想使用ASP.NET 4 WebSite模板的默认登录页面。 What should I change if user is past validation? 如果用户过去验证,我应该更改什么?

This is my Login button 这是我的登录按钮

protected void LoginButton_Click(object sender, EventArgs e)
{
    string userName = LoginUser.UserName;
    string password = LoginUser.Password;

    DBAccess dba = new DBAccess();
    DataTable dt = dba.GetUser(userName, password);

    if (dt.Rows.Count > 0)
    {
        Session["UserID"] = dt.Rows[0]["UserID"].ToString();
        string name = dt.Rows[0]["FirstName"].ToString() + " " + dt.Rows[0]["LastName"].ToString();
        FormsAuthentication.SetAuthCookie(userName, true);

    }
    else
    {
        LoginUser.FailureText = "Wrong Password or User Name";
    }
}

How to change HeadLoginStatus and how to set Authentication to True? 如何更改HeadLoginStatus以及如何将Authentication设置为True?

Thank you for any help! 感谢您的任何帮助!

要登录用户,请使用以下命令:

FormsAuthentication.RedirectFromLoginPage(userName,yourRememberMeCheckBox.Checked);

Actually I realized, that Log in will work with any methods, that redirect you to another page. 实际上我意识到,登录将使用任何方法,将您重定向到另一个页面。 So I could use next variations: 所以我可以使用下一个版本:

FormsAuthentication.RedirectFromLoginPage(userName,yourRememberMeCheckBox.Checked);

Or 要么

Response.Redirect("Default.aspx");

Or 要么

Server.Transfer("Default.aspx");

All the time you will authorize user 您将一直授权用户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM