Jesoba.com is launched, Click below image to access it

Jesoba.com is launched, Click below image to access it
Technology and Entertainment Blog

How To Create Login Page and Redirect Main Page Using C# in ASP.Net.

Title : How To Create Login Page and Redirect Main Page Using C# in ASP.Net.

Article ID : ASP0002

Description : This code will help you to understand how to login and redirect another page.

Source Code :

using System;
using System.Collections.Generic;
using System.Web;

using System.Linq;

using System.Data.SqlClient;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
 
    string  sSqlStr;
    SqlDataReader dr;
    SqlConnection con;
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {

        }
    }
    protected void btnlogin_Click(object sender, EventArgs e)
    {
        con = new SqlConnection(@"Data Source=.\SQL2005; Initial Catalog=VSPLHR2011; Integrated Security = True");
        con.Open();
        sSqlStr = "select * from UserLogin where l_UserId ='" + txtusername.Text + "' And l_Pass='" + txtpass.Text + "'";
        SqlCommand cmd = new SqlCommand(sSqlStr, con);
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        { 
                Response.Redirect("Default3.aspx");
        }
        else
        {
           
            Label18.Text = "Please enter correct user name & password";
            txtusername.Text = "";
            txtpass.Text = "";
            txtusername.Focus();
        }
        con.Close();
    }
}

Image/Video :  In this if you enter wrong username and password it will display
                         error  in red label.otherwise it will login & redirect to main page.
                         Click on Images:



Keyword : SQL Server Connection, Execute Select Query, Login Page, Redirect Page.

Reference : N/A

No comments:

Google+ Badge

About Author

My photo

I am Senior Server Expert and Professional Blogger.