简体   繁体   中英

Asp.net Membership provider with custom textboxes to login

I installed ASPNET Membership provider.Now i create a Login form(This is not a default asp.net login form).But i saw lots of example in internet they use default login page.. So. i wanted to know how to do login with this?

My aspx code here

<form  name="form-area"  class="form-area" runat="server">
                    <h1>User Login</h1>
                    <p>Please Enter Username & Password to login</p>
                    <asp:TextBox ID="txtusr" runat="server" ></asp:TextBox>
                    <asp:TextBox ID="txtpw" runat="server" TextMode="Password" ></asp:TextBox>
                    <asp:Button ID="submit" runat="server" Text="Submit" />
                    <div class="form-area-bottom">&nbsp;</div>
                </form>

Here i create a User Roles in ASPNET administration website.I wanted to know about when button click how to Login

I saw some example like this..Can i use this

protected void loginUser_Authenticate(object sender, AuthenticateEventArgs e)
{
    bool isLogin = Membership.ValidateUser(loginUser.UserName, loginUser.Password);
    if (isLogin)
    {
        loginUser.Visible = true;
        Session["user"] = User.Identity.Name;
        FormsAuthentication.RedirectFromLoginPage(loginUser.UserName, true);
        Response.Redirect("Default.aspx");
    }
}

the core off all is

 bool isLogin = Membership.ValidateUser(loginUser.UserName, loginUser.Password);

but you take care to handles the correct event. you're using custom login form so you need to intercept click button validate user within that event.then you can perform the action that you need.

i hope that can help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM