對於Web服務和WCF我很綠,而且我正在使用Windows集成身份驗證 - 如何在服務器端界面上獲取用戶名?我相信我應該實現一個自定義的行爲,或者可能是WCF會話的東西?任何線索都會超級方便。從WCF服務器端獲取Windows用戶名
20
A
回答
9
這裏的服務代碼片段展示瞭如何獲取並使用與WCF服務的調用相關的的WindowsIdentity。
此代碼假設您正在接受配置的大部分默認值。它應該在命名管道或網絡TCP綁定中沒有任何問題。
p.Demand()將確定用戶是否位於由permissionGroup變量指定的窗口組中。
private static void DemandManagerPermission()
{
// Verify the use has authority to proceed
string permissionGroup = ConfigurationManager.AppSettings["ManagerPermissionGroup"];
if (string.IsNullOrEmpty(permissionGroup))
throw new FaultException("Group permissions not set for access control.");
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
var p = new PrincipalPermission(ServiceSecurityContext.Current.WindowsIdentity.Name, permissionGroup, true);
p.Demand();
}
-2
49
嘗試尋找在ServiceSecurityContext.Current.WindowsIdentity
5
要獲得WCF服務調用者的用戶名:
VAR callerUserName = ServiceSecurityContext.Current.WindowsIdentity.Name;
相關問題
- 1. 從服務器端使用Java獲取Windows用戶帳戶名稱
- 2. wcf客戶端配置沒有從服務器獲取值app.config
- 3. 通過WCF數據服務獲取Windows用戶名(Silverlight)
- 4. 從服務器獲取Windows登錄名
- 5. 嘗試獲取使用WCF客戶端的Windows用戶名
- 6. 從客戶端請求,服務器端獲取Active Directory用戶?
- 7. ASP .NET - 在Windows Server 2003(終端服務)上獲取用戶名?
- 8. 在WCF Web服務內部處理WCF Windows服務客戶端
- 9. WCF:從服務器端
- 10. WCF服務器/客戶端回調,從客戶端到服務器的回覆
- 11. 從WCF客戶端調用ServiceStack服務
- 12. 如何從WCF服務獲取客戶端的URL?
- 13. (WCF)如何獲取我的服務中登錄客戶端的用戶名?
- 14. 從客戶端獲取用戶列表的身份服務器
- 15. 從客戶端以校長在WCF的服務服務器
- 16. 從WCF服務獲取JSON
- 17. WCF的命名空間Web.config,客戶端和服務器端,maxReceivedMessageSize
- 18. WCF的服務器/客戶端conected客戶服務器
- 19. 如何獲取WCF調用服務端的用戶名和密碼?
- 20. 從服務器端獲取的客戶端變量(express.js,node.js中)
- 21. 從客戶端獲取值到服務器端(node.js + express.js)
- 22. 從SQL Server(服務器端)獲取數據到JavaScript(客戶端)
- 23. 如何從服務器端代碼獲取客戶端timeZoneOffset
- 24. 如何獲取Windows Azure移動服務用戶的用戶名?
- 25. Windows服務:用戶登錄時獲取用戶名
- 26. 用WCF數據服務在服務器端用戶篩選
- 27. 從Windows Azure服務獲取客戶端IP地址
- 28. 從WCF服務調用WCF服務時獲取異常
- 29. 爲什麼命名管道WCF服務拒絕Windows服務客戶端?
- 30. WCF從WCF服務獲取實體
p.Demand將要求「Thread.CurrentPrincipal」處於指定角色AND具有與「ServiceSecurityContext.Current」相同的用戶名.WindowsIdentity.Name`。 – Joe 2015-11-13 14:22:27