3

I have SQL Database with all my users. I want to use default login page of ASP.NET 4 WebSite Template. 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?

Thank you for any help!

4

2 回答 2

2

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

FormsAuthentication.RedirectFromLoginPage(userName,yourRememberMeCheckBox.Checked);
于 2013-09-13T00:56:37.850 回答
0

实际上我意识到,登录可以使用任何方法,将您重定向到另一个页面。所以我可以使用下一个变体:

FormsAuthentication.RedirectFromLoginPage(userName,yourRememberMeCheckBox.Checked);

或者

Response.Redirect("Default.aspx");

或者

Server.Transfer("Default.aspx");

您将始终授权用户

于 2013-09-13T01:57:23.877 回答