我有一个在Windows身份验证模式下运行的Web服务。
我有一个应用程序来发送asmx连接文本:
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
BasicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
EndpointAddress endpoint = new EndpointAddress("http://xyzts/Service.asmx");
WS_SPIL.ServiceSoapClient client = new WS_SPIL.ServiceSoapClient(basicHttpBinding, endpoint);
client.ClientCredentials.Windows.AllowedImpersonationLevel = Sytem.Security.Principal.TokenImpersonationLevel.Impersonation;
client.ChannelFactory.Credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
我执行以下代码(在ASMX上):User.Identity.Name,它返回我的Windows AD登录。
到目前为止一切顺利。
现在我想用登录用户连接到数据库。 但是我收到的错误消息是当前用户(IIS用户)没有连接到sql server的权限。
try
{
SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
csb.DataSource = "sqlservername";
csb.InitialCatalog = "DBName";
csb.IntegratedSecurity = true;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = csb.ToString();
conn.Open();
conn.Close();
return "ok";
}
catch (Exception ex)
{
return ex.ToString();
}