SpnEndpointIdentity 构造函数

定义

初始化 SpnEndpointIdentity 的新实例。

重载

SpnEndpointIdentity(Claim)

使用指定的标识声明初始化 SpnEndpointIdentity 的新实例。

SpnEndpointIdentity(String)

使用指定的服务主体名称 (SPN) 初始化 SpnEndpointIdentity 的新实例。

SpnEndpointIdentity(Claim)

Source:
SpnEndpointIdentity.cs
Source:
SpnEndpointIdentity.cs

使用指定的标识声明初始化 SpnEndpointIdentity 的新实例。

public:
 SpnEndpointIdentity(System::IdentityModel::Claims::Claim ^ identity);
public SpnEndpointIdentity (System.IdentityModel.Claims.Claim identity);
new System.ServiceModel.SpnEndpointIdentity : System.IdentityModel.Claims.Claim -> System.ServiceModel.SpnEndpointIdentity
Public Sub New (identity As Claim)

参数

identity
Claim

此服务主体名称 (SPN) 的标识。

例外

identitynull

identity 的声明类型不是 Spn

示例

下面的代码演示如何从一组声明中创建标识。

private SpnEndpointIdentity CreateIdentityFromClaimSet(ClaimSet claims)
{
    foreach (Claim claim in claims.FindClaims(null, Rights.Identity))
    {
        return new SpnEndpointIdentity(claim);
    }
    return null;
}
Private Function CreateIdentityFromClaimSet(ByVal claims As ClaimSet) As SpnEndpointIdentity
    For Each claim As Claim In claims.FindClaims(Nothing, Rights.Identity)
        Return New SpnEndpointIdentity(claim)
    Next claim
    Return Nothing
End Function

注解

该构造函数将 SpnLookupTime 属性设置为 1 分钟。

适用于

SpnEndpointIdentity(String)

Source:
SpnEndpointIdentity.cs
Source:
SpnEndpointIdentity.cs

使用指定的服务主体名称 (SPN) 初始化 SpnEndpointIdentity 的新实例。

public:
 SpnEndpointIdentity(System::String ^ spnName);
public SpnEndpointIdentity (string spnName);
new System.ServiceModel.SpnEndpointIdentity : string -> System.ServiceModel.SpnEndpointIdentity
Public Sub New (spnName As String)

参数

spnName
String

SPN。

例外

spnNamenull

示例

下面的代码演示如何从 SPN 的字符串表示形式创建标识。

static EndpointIdentity CreateSpnIdentity()
{
    WindowsIdentity self = WindowsIdentity.GetCurrent();
    SecurityIdentifier sid = self.User;

    SpnEndpointIdentity identity = null;

    identity = new SpnEndpointIdentity(string.Format(CultureInfo.InvariantCulture, "host/{0}", GetMachineName()));

    return identity;
}
static string GetMachineName()
{
    return Dns.GetHostEntry(string.Empty).HostName;
}
Private Shared Function CreateSpnIdentity() As EndpointIdentity
    Dim self As WindowsIdentity = WindowsIdentity.GetCurrent()
    Dim sid As SecurityIdentifier = self.User

    Dim identity As SpnEndpointIdentity = Nothing

    identity = New SpnEndpointIdentity(String.Format(CultureInfo.InvariantCulture, "host/{0}", GetMachineName()))

    Return identity
End Function
Private Shared Function GetMachineName() As String
    Return Dns.GetHostEntry(String.Empty).HostName
End Function

注解

该构造函数将 SpnLookupTime 属性设置为 1 分钟。

适用于