我正在尝试使用 WCF 数据服务为我的 silverlight 4 应用程序获取 Windows 用户名。当我从本地计算机调试应用程序时,我看到了用户名。但是当我从 Web 服务器运行应用程序时,用户名显示为空。如果您需要任何其他详细信息,请告诉我。任何帮助是极大的赞赏。
这是我用来获取用户名的方法:
[OperationContract]
public string GetWindowsUsername()
{
string usr = HttpContext.Current.User.Identity.Name;
return usr.ToString();
}
这是我的 Web.Config :
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime maxRequestLength="2147483647" />
<authentication mode="Windows" />
<!--<anonymousIdentification enabled="true"/>-->
<authorization>
<allow users="*"/>
</authorization>
<!--<identity impersonate="false" />-->
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="OrderTrackingSystem.Web.OTSService.customBinding0"
maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" transferMode="Streamed">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security>
<transport clientCredentialType="Ntlm" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service name="OrderTrackingSystem.Web.OTSService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="OrderTrackingSystem.Web.OTSService.customBinding0"
name="OTSServiceCustom" contract="OrderTrackingSystem.Web.OTSService" />
</service>
</services>
</system.serviceModel>
这是我的服务配置:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="OTSServiceCustom" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:49458/OTSService.svc" binding="basicHttpBinding"
bindingConfiguration="OTSServiceCustom" contract="OTSProxy.OTSService"
name="OTSServiceCustom" />
</client>
</system.serviceModel>
</configuration>