简体   繁体   English

ASP.NET C#登录重定向

[英]ASP.NET C# Login Redirect

I currently have designed a ASP.NET website which has a login page as its home. 我目前已经设计了一个ASP.NET网站,该网站以登录页面为主页。

At present I'm using a response.redirect command to forward valid logins to a specific page. 目前,我正在使用response.redirect命令将有效登录名转发到特定页面。

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. 我已经使用Client_ID设置了用户数据库,希望使用它来重定向到页面。

eg 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. 例如,Client_ID1.aspx将转发Client_ID为1的登录用户。Client_ID2.aspx将转发Client_ID为2的登录用户。Client_ID3.aspx将转发Client_ID为3的登录用户。

My issue is how do I write the response.redirect page with a variable on the end. 我的问题是如何编写带有结尾变量的response.redirect页面。 The code would need to get the Client_ID number from the database and then redirect. 该代码将需要从数据库中获取Client_ID号,然后进行重定向。

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. 用户的设置由我在管理页面上完成,因此我控制Client_ID部分的设置而不是用户。

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? }对此有什么帮助吗?

You can try the following: 您可以尝试以下方法:

int index = realURL.IndexOf("."); int index = realURL.IndexOf(“。”);

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

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

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); 您也可以将页面本身存储在db中,然后可以调用Response.Redirect(client_type);。 and use the string returned directly. 并使用直接返回的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM