Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.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
Sql 在模拟中设置窗体身份验证_Sql_Asp.net_Windows Authentication_Impersonation - Fatal编程技术网

Sql 在模拟中设置窗体身份验证

Sql 在模拟中设置窗体身份验证,sql,asp.net,windows-authentication,impersonation,Sql,Asp.net,Windows Authentication,Impersonation,我有一个内部网站。我的数据库使用windows身份验证。我的网站通过使用logonuser()使用网络凭据 IntPtr token = IntPtr.Zero; bool result = LogonUser(txtUsername.Text, txtDomain.Text, txtPassword.Text, 2, 0, ref token); //2, 0, ref token); if (result) { Win

我有一个内部网站。我的数据库使用windows身份验证。我的网站通过使用
logonuser()
使用网络凭据

IntPtr token = IntPtr.Zero;

        bool result = LogonUser(txtUsername.Text, txtDomain.Text, txtPassword.Text, 2, 0, ref token); //2, 0, ref token);
        if (result)
        {
            WindowsIdentity newId = new WindowsIdentity(token);
            WindowsImpersonationContext impersonatedUser = newId.Impersonate();
            FormsAuthentication.SetAuthCookie(txtDomain.Text + "\\" + txtUsername.Text, false);
            using (SqlConnection cnn=new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
            {
                using (SqlCommand cmd=new SqlCommand("select * from [user] where username=@user", cnn))
                {
                    cmd.Parameters.Clear();
                    cmd.Parameters.AddWithValue("@user",txtDomain.Text+"\\"+txtUsername.Text);

                    cnn.Open();
                    SqlDataReader rdr=cmd.ExecuteReader();
                    rdr.Read();
                    if(rdr.HasRows)
                    {   
                        cnn.Close();
                        lblNotification.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
                        Session.Add("principal", new WindowsPrincipal(newId));
                    }
                    else
                    {
                        lblNotification.Text="Username or Password is Invalid";
                    }
                }
            }
代码正确执行,包括sql,但当它转到下一页(home.aspx)时,我得到以下错误:

在sql中的windows身份验证中遇到错误。'“ECP”是我的域名,“PHAPPCVTL002198$”是我的计算机名,但我没想到会是这样。我希望在登录表单中输入用户名