ローカルIISでホストされているASP.NETページにアクセスしているクライアントのWindowsユーザ名を取得しようとしています。私は、クライアントのWindowsユーザ名を返すASP.NETページ内のWCFサービスを呼び出しています。私はについて、それらのほとんどはWCFを使用してクライアントのWindowsユーザ名を取得しようとしています
- OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name
- HttpContext.Current.User.Identity.Name
- HttpContext.Current.Userことを示唆しているように多くの記事に出くわしました。 Identity.Name
私が直面している問題は、 "1"は常にNullを返すことです。 "2"と "3"は常にローカルユーザー名を返し、要求ユーザーの名前は返しません。 ASP.NETとWCFサービスの両方のweb.configsに何かがありませんか?
IISプロパティ:Windows統合認証が有効です。
ここにコードがあります。
WCF
public string GetWindowsUser()
{
string temp = OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;
string temp1 = HttpContext.Current.User.Identity.Name;
string temp2 = HttpContext.Current.User.Identity.Name;
return "Temp: "+temp+" \nTemp1: "+temp1+" \nTemp2: "+temp2;
}
web.configファイル
<system.web>
<compilation debug="false" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:4772/Services.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="WindowsAuthServices.IService1" name="BasicHttpBinding_IService1"/>
</client>
</system.serviceModel>
ASP.NETページ:
protected void Page_Load(object sender, EventArgs e)
{
WindowsAuthServices.Service1Client client = new WindowsAuthServices.Service1Client();
lblWelcome.Text = client.GetWindowsUser();
}
のWeb.Config
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:4772/Services.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="WindowsAuthServices.IService1" name="BasicHttpBinding_IService1"/>
</client>
</system.serviceModel>
あなたがやろうとしていることを止めて教えてください。 –
当社の企業は、会社のデバイス(ラップトップ)を使用しているサイトだけを開設したいと考えています。そのため、SharePointサイトでWindows認証を使用し、ユーザー名とパスワードを要求しないようにします。ウィンドウのユーザー名が承認されたユーザーの一覧にあるユーザー名と一致する場合は、別の認証ページにリダイレクトされます。第1部を終わらせることは問題でした。 – Santosh