title: How to login with "username" instead of "email address" in ASP.Net Web Forms Identity
body: <p>I need to set my login to use username instead of email address, how can I change it?
  I've looked everywhere but they are MVC codes not web forms.</p>
  
  <p>I appreciate your efforts in reaching a solution for my problem.</p>
  
  <pre><code>using System;
  using System.Web;
  using System.Web.UI;
  using Microsoft.AspNet.Identity;
  using Microsoft.AspNet.Identity.Owin;
  using Owin;
  using Web_WebApp.Models;
  
  namespace Web_WebApp.Account
  {
      public partial class Login : Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
              RegisterHyperLink.NavigateUrl = "Register";
              // Enable this once you have account confirmation enabled for password reset functionality
              //ForgotPasswordHyperLink.NavigateUrl = "Forgot";
              OpenAuthLogin.ReturnUrl = Request.QueryString["ReturnUrl"];
              var returnUrl = HttpUtility.UrlEncode(Request.QueryString["ReturnUrl"]);
              if (!String.IsNullOrEmpty(returnUrl))
              {
                  RegisterHyperLink.NavigateUrl += "?ReturnUrl=" + returnUrl;
              }
          }
  
          protected void LogIn(object sender, EventArgs e)
          {
              if (IsValid)
              {
                  // Validate the user password
                  var manager = Context.GetOwinContext().GetUserManager&lt;ApplicationUserManager&gt;();
                  var signinManager = Context.GetOwinContext().GetUserManager&lt;ApplicationSignInManager&gt;();
  
                  // This doen't count login failures towards account lockout
                  // To enable password failures to trigger lockout, change to shouldLockout: true
                  var result = signinManager.PasswordSignIn(UserName.Text, Password.Text, RememberMe.Checked, shouldLockout: false);
  
                  switch (result)
                  {
                      case SignInStatus.Success:
                          IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
                          break;
                      case SignInStatus.LockedOut:
                          Response.Redirect("/Account/Lockout");
                          break;
                      case SignInStatus.RequiresVerification:
                          Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&amp;RememberMe={1}", 
                                                          Request.QueryString["ReturnUrl"],
                                                          RememberMe.Checked),
                                            true);
                          break;
                      case SignInStatus.Failure:
                      default:
                          FailureText.Text = "Invalid login attempt";
                          ErrorMessage.Visible = true;
                          break;
                  }
              }
          }
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>using System;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using Microsoft.AspNet.Identity;
  using Microsoft.AspNet.Identity.Owin;
  using Owin;
  using Web_WebApp.Models;
  
  
  namespace Web_WebApp.Account
  {
      public partial class Register : Page
      {
          protected void CreateUser_Click(object sender, EventArgs e)
          {
  
              var manager = Context.GetOwinContext().GetUserManager&lt;ApplicationUserManager&gt;();
              var signInManager = Context.GetOwinContext().Get&lt;ApplicationSignInManager&gt;();
              var user = new ApplicationUser() { UserName = UserName.Text, Email = Email.Text, FirstName = FirstName.Text, MiddleName = MiddleName.Text, LastName = LastName.Text };
              IdentityResult result = manager.Create(user, Password.Text);
              if (result.Succeeded)
              {
                  // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                  //string code = manager.GenerateEmailConfirmationToken(user.Id);
                  //string callbackUrl = IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
                  //manager.SendEmail(user.Id, "Confirm your account", "Please confirm your account by clicking &lt;a href=\"" + callbackUrl + "\"&gt;here&lt;/a&gt;.");
  
                  signInManager.SignIn( user, isPersistent: false, rememberBrowser: false);
                  IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
              }
              else 
              {
                  ErrorMessage.Text = result.Errors.FirstOrDefault();
              }
          }
      }
  }
  </code></pre>