我有一個使用Windows身份驗證的WCF服務的Silverlight應用程序。 我的用戶獲得了正確的身份驗證。我可以在客戶端訪問他們的用戶名和角色。 但是我如何在服務器端做同樣的事情呢? 我已經試過這如何在WCF服務上使用Windows身份驗證訪問服務器端的用戶名?
ServiceSecurityContext.Current.WindowsIdentity
和
IIdentity caller = ServiceSecurityContext.Current.PrimaryIdentity;
這是我發現的在這裏計算器類似的問題的答案,但它不編譯。 我得到'ServiceSecurityContext不包含當前'定義的異常。
那麼如何讓服務器端的用戶?
如果該服務已被設置爲ASP.NET兼容模式這隻會工作。 – syneptody
真的嗎?這不是從請求頭獲取用戶名嗎? –
根據:http://msdn.microsoft.com/en-us/library/aa702682.aspx「HttpContext:當從WCF服務中訪問時,Current始終爲空,請改用RequestContext。」 ...除非您的服務使用ASP.NET兼容 – syneptody