login.aspx参数不正确

时间:2017-02-02 01:31:28

标签: c# asp.net

参数不正确

var user = manager.Find(txtUserName.Text, txtPassword.Text);

代码

public partial class Pages_Account_Login : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSignIn_OnClick(object sender, EventArgs e)
    {
        UserStore<IdentityUser> userStore = new UserStore<IdentityUser>();

        userStore.Context.Database.Connection.ConnectionString =
            System.Configuration.ConfigurationManager.
            ConnectionStrings["GarageConnectionString"].ConnectionString;

        UserManager<IdentityUser> manager = new UserManager<IdentityUser>(userStore);

        var user = manager.Find(txtUserName.Text, txtPassword.Text);
        try
        {
                if (user != null)
                {
                    //Call OWIN functionality
                    var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                    var userIdentity = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);

                    //Sign in user
                    authenticationManager.SignIn(new AuthenticationProperties
                    {
                        IsPersistent = false
                    }, userIdentity);

                    //Redirect user to homepage
                    Response.Redirect("~/Index.aspx");
                }
               else
                    litErrorMsg.Text = "Invalid username or password";
                }
      }
        catch(Exception)
       {
         litErrorMsg.Text = "Invalid username or password";

       }
    }
}

0 个答案:

没有答案