0

I currently have designed a ASP.NET website which has a login page as its home.

At present I'm using a response.redirect command to forward valid logins to a specific page.

What I would like to do is forward the user to their own page?

I have setup the user database with a Client_ID with the hope of using this to redirect to the page.

e.g. Client_ID1.aspx would forward login users with a Client_ID number of 1. Client_ID2.aspx would forward login users with a Client_ID number of 2. Client_ID3.aspx would forward login users with a Client_ID number of 3.

My issue is how do I write the response.redirect page with a variable on the end. The code would need to get the Client_ID number from the database and then redirect.

The setup of users is done by me on an admin page therefore I control the setup of the Client_ID part not the user.

This is my code I have when the user clicks the login button:

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
    conn.Open();
    string checkuser = "select count(*) from UserData where UserName='" + TextBoxUserName.Text + "'";
    SqlCommand com = new SqlCommand(checkuser, conn);
    int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
    conn.Close();
    if (temp == 1)
    {
        conn.Open();
        string checkPasswordQuery = "select password from UserData where UserName='" + TextBoxUserName.Text + "'";
        SqlCommand passComm = new SqlCommand(checkPasswordQuery, conn);
        string password = passComm.ExecuteScalar().ToString().Replace(" ","");
        if(password == TextBoxPassword.Text)
        {
            Session["New"] = TextBoxUserName.Text;
            Response.Write("Password is correct");
            Response.Redirect("Manager.aspx");
        }
        else
        {
            Response.Write("Password is Not correct");
        }

    }
    else
    {
        Response.Write("User Name is Not correct");                
    }
}

} Any help on this please?

2 Answers 2

1

You can try the following:

int index = realURL.IndexOf(".");

string url = realURL.Substring(0, index);

Response.Redirect(url + clientId.ToString() + ".aspx");

Sign up to request clarification or add additional context in comments.

1 Comment

Will give this ago, if it helps I have included my click button code in original post. Thanks for your reply J
0
string client_type = getClientTypeFromDB();
switch (client_type)
{
    case "Type1":
        Response.Redirect("~/client1.aspx");
        break;

    case "Type2":
        Response.Redirect("~/client2.aspx");
        break;

    case "Type3":
        Response.Redirect("~/client3.aspx");
        break;
}

You could also store the page itself in the db, and then you could call Response.Redirect(client_type); and use the string returned directly.

1 Comment

Hi, Not sure how to implement into my code. I have included my click button code in the original post. Would it be easier & more secure to include in the DB? I would have alot of Client_ID pages so would like to code once and then control via the DB which was my original plan. Thanks J

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.