我正在嘗試使用WCF數據服務獲取我的Silverlight 4應用程序的Windows用戶名。我在從本地計算機調試應用程序時看到了用戶名。但是,當我從Web服務器運行應用程序時,用戶名會以空值出現。 請讓我知道你是否需要任何其他細節。任何幫助是極大的讚賞。通過WCF數據服務獲取Windows用戶名(Silverlight)
這裏是我使用來獲取用戶名的方法:
[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>
檢查此http://stackoverflow.com/q/292233/860243 – Flowerking 2013-02-11 16:52:41
這不適合我,因爲我不尋找認證。我只需要Windows用戶名,我也看了另一篇文章。我得到當前爲空。 – user2062004 2013-02-11 17:43:48