簡體   English   中英

從服務端訪問WCF身份驗證信息

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM