Tuesday, March 4, 2014

ASP default Login form using C#

To use the ASP default Login form you need to add a login control into your web form .



To add this control you need to go to the Login tab and select the Login control. Drag and drop the control into the web from and create an event named Login1_Authenticate by double clicking on the login control.

Here you will access the User Name as Login1.UserName and Password as Login1.Password. You can check it statically or dynamically using database. before that check the article to connect the database and how to execute database query in C#.

Write the below code in the event generated.

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        if (Login1.UserName == "admin" && Login1.Password == "admin")
        {
            //Response.Write("<script>alert('right');</script>");
            Response.Redirect("Default.aspx");
        }
    }

you don't need to add any else option because ASP has a default else option to show wrong user-name & password. I have done it here statically but you can do it using database(dynamically).


In general we don't use this tool in professional level, but you can use it in some small projects to do the code in a shorter way.

Enjoy the code.

0 comments:

Post a Comment

Follow by Email

Popular Posts

Pageviews