Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 能够从当前登录的用户会话c中检索更多信息_C#_Sql_Session_Login_Information Retrieval - Fatal编程技术网

C# 能够从当前登录的用户会话c中检索更多信息

C# 能够从当前登录的用户会话c中检索更多信息,c#,sql,session,login,information-retrieval,C#,Sql,Session,Login,Information Retrieval,我已经创建了一个c登录,它检查我的SQL数据库中的用户名和密码是否正确,如果登录凭据正确,它将创建一个名为correct的会话 在名为StaffTypeID的表中,登录信息来自该表,我还有一个StaffTypeID,它链接到另一个名为staff types的表。在我的员工类型中有管理员、主管等 我需要从当前用户会话中检索StaffTypeID,在这样做后,我将能够为当前用户提供对系统某些部分的相关访问权限。有没有办法做到这一点 这是我的登录码: SqlConnection loginConnec

我已经创建了一个c登录,它检查我的SQL数据库中的用户名和密码是否正确,如果登录凭据正确,它将创建一个名为correct的会话

在名为StaffTypeID的表中,登录信息来自该表,我还有一个StaffTypeID,它链接到另一个名为staff types的表。在我的员工类型中有管理员、主管等

我需要从当前用户会话中检索StaffTypeID,在这样做后,我将能够为当前用户提供对系统某些部分的相关访问权限。有没有办法做到这一点

这是我的登录码:

SqlConnection loginConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["LabelsDressShopConnection"].ConnectionString);
loginConnection.Open();
string checkUser = "select count(*) from Staff where EmailAddress ='" + txtEmail.Text + "'";
SqlCommand compair = new SqlCommand(checkUser, loginConnection);
int tempVar = Convert.ToInt32(compair.ExecuteScalar().ToString());

loginConnection.Close();

if (tempVar == 1)
{
    loginConnection.Open();
    string checkUserPassword = "select Password from Staff where EmailAddress ='" + txtEmail.Text + "'"; ;

    SqlCommand passComm = new SqlCommand(checkUserPassword, loginConnection);
    string password = passComm.ExecuteScalar().ToString().Replace(" ","");

    if (password == txtPassword.Text) {
        Session["correct"] = txtEmail.Text;
        Response.Redirect("Default.aspx");
    }
    else {
        Response.Write("Username or Password incorrect");
    }
}
else {
    Response.Write("Username or Password incorrect");
}

不要信任来自浏览器的任何值,即代码易受SQL注入的影响。请从executescalar切换到executereader,并将stafftypeid添加到密码查询中。请参阅关于如何使用executereader@WorkSmarter的这篇文章谢谢您的评论,我将大胆地看一看并尝试重新编写我的代码: