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 で) 実行します: Windows AD ログインを返す User.Identity.Name。
ここまでは順調ですね。
今、私はログインユーザーでデータベースに接続したいと考えています。しかし、現在のユーザー (IIS ユーザー) には SQL サーバーに接続する権限がないというエラー メッセージが表示されます。
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();
}