2010-12-22 95 views
3

我正在使用UserNamePasswordValidator類作爲使用WCF的UserName安全性的一部分。這一切都很好,並且類的Validate函數被調用並正常工作。WCF UserNamePasswordValidator - 驗證後訪問憑據

那我怎麼才能知道UserName用在我的服務功能中?

例如說,如果一個客戶端連接,並要求使用類似

IList<Log> Logs() { ... } 

該功能如何才能知道哪些用戶名是對請求中使用日誌列表?

我想要做的是記錄什麼用戶名稱調用服務內的什麼功能。

回答

9

不知道,但你可能會尋找

var userName = OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name; 
+0

非常感謝! – Chris 2010-12-22 16:49:25

1

我相信是有東西在操作環境。試試這個:

OperationContext oc = OperationContext.Current; 
ServiceSecurityContext ssc = oc.ServiceSecurityContext; 
string client = ssc.PrimaryIdentity.Name;