2017-06-01 86 views
2

因爲我想將自定義聲明添加到我的應用程序中,我檢查了ClaimTypes的源代碼(使用JetBrains反編譯器進行反編譯)。這是它的一塊:索賠類型的網址是什麼

namespace System.Security.Claims 
{ 
    /// <summary>Defines constants for the well-known claim types that can be assigned to a subject. This class cannot be inherited.</summary> 
    [ComVisible(false)] 
    public static class ClaimTypes 
    { 
    internal const string ClaimTypeNamespace = "http://schemas.microsoft.com/ws/2008/06/identity/claims"; 
    /// <summary>The URI for a claim that specifies the instant at which an entity was authenticated; http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationinstant.</summary> 
    public const string AuthenticationInstant = "http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationinstant"; 
    /// <summary>The URI for a claim that specifies the method with which an entity was authenticated; http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod.</summary> 
    public const string AuthenticationMethod = "http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod"; 
    /// <summary>The URI for a claim that specifies the cookie path; http://schemas.microsoft.com/ws/2008/06/identity/claims/cookiepath.</summary> 
    public const string CookiePath = "http://schemas.microsoft.com/ws/2008/06/identity/claims/cookiepath"; 
    /// <summary>The URI for a claim that specifies the deny-only primary SID on an entity; http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarysid. A deny-only SID denies the specified entity to a securable object.</summary> 
    public const string DenyOnlyPrimarySid = "http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarysid"; 
    /// <summary>The URI for a claim that specifies the deny-only primary group SID on an entity; http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarygroupsid. A deny-only SID denies the specified entity to a securable object.</summary> 
    public const string DenyOnlyPrimaryGroupSid = "http://schemas.microsoft.com/ws/2008/06/identity/claims/denyonlyprimarygroupsid"; 

我的問題是(我希望它不是太傻),什麼網址?他們在別的地方用過嗎?當我嘗試打開一個URL時,我的資源管理器顯示該網站未找到。所以我認爲沒有xml-schema或其他東西。 如果我添加了我的自定義聲明,是否還需要添加類似這些URL的內容?

回答

2

這些是ClaimTypes,它表示實體可以聲明的預定義類型的聲明。你提到的是從WIF,這裏是IdentityModel ClaimTypes。

已知的索賠類型會自動反序列化到上下文中。像http://schemas.microsoft.com/ws/2008/06/identity/claims/role作爲角色添加到user.roles集合(用於IsInRole)。

所以類型不是隨機的,而是按規格。你可以添加你自己的類型。這可以是任何字符串,但也可以使用相同的格式。

假設你添加客戶編號權利要求,那麼你就需要通過claimtype="CustomerId"查詢聲明集合,或者您定義的URI(比如:http://schemas/mycompany.com/2017/06/identity/CustomerId)。

您可以通過代碼或通過在Identity.Claims表中插入記錄添加聲明。

+1

你是不是指'http://schemas.mycompany ...'? – xr280xr