Question

I'm using the ASP.NET membership provider on my website. It works fine while using the Login Control in Visual Studio. However, I feel the Login Control has its limitation and I'm having a hard time making it fit to the design of my page. So instead of using that Login control, I'd like to be able to just create two TextBox's and a Button myself and use that to login instead. So my question is, can I create a custom login page with by creating my own textbox's and buttons? The code behind Login.aspx that I use with the login control right now looks like this:

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
    if (Membership.ValidateUser(Login1.UserName, Login1.Password) == true)
    {
        Login1.Visible = true;
        Session["user"] = User.Identity.Name;
        FormsAuthentication.RedirectFromLoginPage(Login1.UserName, true);
    }
    else
    {
        Response.Write("Invalid Login");
    }
}

I tried changing Login1.UserName to TextBox1.Text and so on, but that didn't work. Any help is appreciated, thanks!

Was it helpful?

Solution

You should be removing Login1_Authenticate event and have a login button event to validate the credentials.

Or depending on how you submit back to server, such as ajax calls etc. You can also use fiddler to see what's exactly being posted back to server.

PS. Why do not use ASP.net MVC?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top