Sql 在模拟中设置窗体身份验证
我有一个内部网站。我的数据库使用windows身份验证。我的网站通过使用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
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$”是我的计算机名,但我没想到会是这样。我希望在登录表单中输入用户名