Я пытаюсь получить имя пользователя Windows клиента, который обращается к странице ASP.NET, размещенной на моем локальном IIS.Я называю службу WCF на странице ASP.NET, которая возвращает имя пользователя Windows клиента.Я сталкивался с таким количеством сообщений, и большинство из них предлагают, чтобы
- OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name
- HttpContext.Current.User.Identity.Name
- HttpContext.Current.User.Identity.Name
должно работать.Проблемы, с которыми я сталкиваюсь, это «1», всегда возвращаемое значение Null.«2» и «3» всегда возвращают мое локальное имя пользователя, а не запрашивающее имя пользователя.Я что-то упустил в web.configs как службы ASP.NET, так и службы WCF.
Свойства 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>