且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

登录后无法显示用户名

更新时间:2023-12-03 19:56:04

您只是忘记了实际登录用户.您要做的只是验证用户凭据,然后进行重定向.因此,请尝试在if语句中添加以下行:

You simply forgot to actually login your user. All you do is validating the users credentials and then do a redirect. So try to add the following line in your if-statement:

protected void LoginButton_Click(object sender, EventArgs e)
{
    // Validate the user against the Membership framework user store
    if (Membership.ValidateUser(UserName.Text, Password.Text))
    {
        // Log the user into the site
        FormsAuthentication.SetAuthCookie(UserName.Text, true);
        // Do the redirect
        Response.Redirect("~/Index.aspx");
    }
    // If we reach here, the user's credentials were invalid
    InvalidCredentialsMessage.Visible = true;
}