Automatically login in website by passing Username and Password in QueryString in ASP.Net

Last Reply on Feb 02, 2014 09:51 AM By Azim

Posted on Feb 02, 2014 03:10 AM

I want to use autouser login in my website using ASP.NET C#.

i.e., If I say that autouser login, this means user has to include user id and password to url for verification.

Example: http://10.9.80.210/Rmax/abc.aspx?Username=xyz,Password=1234

Here, 'UserName and password' will be as autouser login, '10.9.80.210/Radmax' is the website url, 'abc.aspx' page is any of the page of website.

I hope i made myself clear.

How to achieve this?

Please reply.

You are viewing reply posted by: Azim on Feb 02, 2014 09:51 AM.
Posted on Feb 02, 2014 09:51 AM

This way

    protected string UserName
    {
        get
        {
            return (Request.QueryString["UserName"]);
        }
    }

    protected string Password
    {
        get
        {
            return (Request.QueryString["Password"]);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            if (this.UserName !=null)
            {
                string userName = this.UserName;
                string password = this.Password;
                this.Login(userName, password);
            }
        }
    }

    private void Login(string name, string password)
    {
        string constr = ConfigurationManager.ConnectionStrings["ConString2"].ConnectionString;
        string sqlStatment = "SELECT * FROM Users Where UserName = @UserName AND Password = @Password";
        using (SqlConnection con = new SqlConnection(constr))
        {
            using (SqlCommand cmd = new SqlCommand(sqlStatment, con))
            {
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                {
                    cmd.Parameters.AddWithValue("@UserName", name);
                    cmd.Parameters.AddWithValue("@Password", password);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        Response.Redirect("Home.aspx");
                    }
                }
            }
        }
    }

Thank you