C# 如何在登录时将用户发送到两个不同的网页

C# 如何在登录时将用户发送到两个不同的网页,c#,asp.net,redirect,C#,Asp.net,Redirect,因此,像员工甚至管理员这样的用户登录到相同的Index.aspx。我想把它改成不同的网页 如何为每个用户类型更改站点。我有不同的用户类型。我在身份验证函数中使用了UserType 为什么不让身份验证方法返回字符串?当用户经过身份验证时,它可以返回用户类型,当身份验证失败时,它可以返回空或null。那你就说 protected static Boolean Authentication(string username, string password) { string sqlstring

因此,像员工甚至管理员这样的用户登录到相同的Index.aspx。我想把它改成不同的网页


如何为每个用户类型更改站点。我有不同的用户类型。我在身份验证函数中使用了UserType

为什么不让身份验证方法返回字符串?当用户经过身份验证时,它可以返回用户类型,当身份验证失败时,它可以返回空或null。那你就说

protected static Boolean Authentication(string username, string password)
{
    string sqlstring;
    sqlstring = "Select Username, Password, UserType from Userprofile WHERE Username='" + username + "' and Password ='" + password + "'";

    // create a connection with sqldatabase 
    System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(
                 "Data Source=PRADEEP-LAPTOP\\SQLEXPRESS;Initial Catalog=BookStore;Integrated Security=True");

    // create a sql command which will user connection string and your select statement string
    System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(sqlstring, con);

    // create a sqldatabase reader which will execute the above command to get the values from sqldatabase
    System.Data.SqlClient.SqlDataReader reader;

    // open a connection with sqldatabase
    con.Open();

    // execute sql command and store a return values in reade
    reader = comm.ExecuteReader();

    // check if reader hase any value then return true otherwise return false
    if (reader.Read())
        return true;
    else
        return false;
}

Boolean blnresult;

blnresult = Authentication(Login2.UserName, Login2.Password);

if (blnresult == true)
{
    Session["User_ID"] = getIDFromName(Login2.UserName);
    Session["Check"] = true;
    Session["Username"] = Login2.UserName;

    Response.Redirect("Index.aspx");
}
if (Session["UserType"] == "admin")
    Response.Redirect("Admin.aspx");
else
    Response.Redirect("Index.aspx");

为什么不让身份验证方法返回字符串?当用户经过身份验证时,它可以返回用户类型,当身份验证失败时,它可以返回空或null。那你就说

if (Session["UserType"] == "admin")
    Response.Redirect("Admin.aspx");
else
    Response.Redirect("Index.aspx");

重构
Authentication
为提供的凭据返回user group或null表示缺少用户,然后在调用者中添加switch或if语句。

重构
Authentication
为提供的凭据返回user group或null表示缺少用户,然后在调用者中添加switch或if语句。

请使用。很多这方面的工作已经以更安全的方式为您完成了

最后,查看可用于登录用户、基于用户显示内容、密码恢复等的内置插件。

请使用。很多这方面的工作已经以更安全的方式为您完成了


最后,查看可用于登录用户、基于用户显示内容、密码恢复等的内置插件。

您有SQL注入漏洞。此外,您不应以纯文本形式存储密码。@SLaks:这不是一个漏洞,这是一种将““”或“=”作为主密码的时髦方式。您有一个SQL注入漏洞。此外,您不应以纯文本形式存储密码。@SLaks:这不是一个漏洞,它是一种将““”或“=”作为主密码的时髦方式。