Displaying the username after login not working

前端 未结 2 807
萌比男神i
萌比男神i 2021-01-23 13:04

I am having trouble displaying the username after login on my index page.

The code I have for Logging in:

protected void btnLoginButton_Click(object send         


        
相关标签:
2条回答
  • 2021-01-23 13:21

    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;
    }
    
    0 讨论(0)
  • 2021-01-23 13:29
    protected void btnLoginButton_Click(object sender, EventArgs e)
    {
        if (Membership.ValidateUser(UserName.Text, Password.Text))
        {
            WelcomeBackMessage.Text = User.Identity.Name.ToString();
            // Log the user into the site
            Response.Redirect("~/Index.aspx");
    
    Place WelcomeBackMessage label in master page and try this code.
    
    0 讨论(0)
提交回复
热议问题