EndpointIdentity.CreateUpnIdentity(String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Creates a user principal name (UPN) identity with a specified name.
public:
static System::ServiceModel::EndpointIdentity ^ CreateUpnIdentity(System::String ^ upnName);
public static System.ServiceModel.EndpointIdentity CreateUpnIdentity (string upnName);
static member CreateUpnIdentity : string -> System.ServiceModel.EndpointIdentity
Public Shared Function CreateUpnIdentity (upnName As String) As EndpointIdentity
Parameters
- upnName
- String
The name for the UPN identity.
Returns
A UPN EndpointIdentity associated with the specified upnName
.
Exceptions
upnName
is null
.
Examples
The following code shows how to call this method.
namespace TestPrincipalPermission
{
class PrincipalPermissionModeWindows
{
[ServiceContract]
interface ISecureService
{
[OperationContract]
string Method1();
}
class SecureService : ISecureService
{
[PrincipalPermission(SecurityAction.Demand, Role = "everyone")]
public string Method1()
{
return String.Format("Hello, \"{0}\"", Thread.CurrentPrincipal.Identity.Name);
}
}
public void Run()
{
Uri serviceUri = new Uri(@"http://localhost:8006/Service");
ServiceHost service = new ServiceHost(typeof(SecureService));
service.AddServiceEndpoint(typeof(ISecureService), GetBinding(), serviceUri);
service.Authorization.PrincipalPermissionMode = PrincipalPermissionMode.UseAspNetRoles;
service.Open();
EndpointAddress sr = new EndpointAddress(
serviceUri, EndpointIdentity.CreateUpnIdentity(WindowsIdentity.GetCurrent().Name));
ChannelFactory<ISecureService> cf = new ChannelFactory<ISecureService>(GetBinding(), sr);
ISecureService client = cf.CreateChannel();
Console.WriteLine("Client received response from Method1: {0}", client.Method1());
((IChannel)client).Close();
Console.ReadLine();
service.Close();
}
public static Binding GetBinding()
{
WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message);
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
return binding;
}
}
}
Remarks
A secure WCF client that connects to an endpoint with this identity uses the UPN when performing SSPI authentication with the endpoint.
This static method creates an instance of UpnEndpointIdentity by calling its constructor, UpnEndpointIdentity, using upnName
as the input parameter.
If upnName
is specified with an empty string, authentication falls back from Kerberos to NTLM if possible. If AllowNtlm is false
, WCF makes a best-effort to throw an exception if NTLM is used. Note that setting this property to false
may not prevent NTLM credentials from being sent over the wire.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기