[英]How do I access username on the server side using Windows authentication on a WCF service?
[英]Access WCF Authentication information from the Service Side
我使用以下代碼對我的WCF服務進行身份驗證:
proxy.ClientCredentials.UserName.UserName = "test";
proxy.ClientCredentials.UserName.Password = "pass";
是否可以通過WCF服務代碼的方法來訪問此信息? (我對使用的密碼不感興趣,更多的是出於審核目的而使用的用戶名。)
我正在嘗試確定調用該方法的用戶的身份,而無需更改方法簽名以包括另一個參數。
您可以像這樣檢索呼叫者的用戶名:
ServiceSecurityContext ssc = ServiceSecurityContext.Current;
if (!ssc.IsAnonymous && ssc.PrimaryIdentity != null)
{
string userName = ServiceSecurityContext.Current.PrimaryIdentity.Name;
}
PrimaryIdentity
將包含一個“普通” IIdentity,並具有身份對象類所攜帶的所有字段(例如IsAuthenticated等)。
渣
您是否嘗試過研究ServiceSecurityContext ?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.