ClaimsPrincipal.CreateFromHttpContext Method (HttpContext, Boolean)
[Starting with the .NET Framework 4.5, Windows Identity Foundation (WIF) has been fully integrated into the .NET Framework. The version of WIF addressed by this topic, WIF 3.5, is deprecated and should only be used when developing against the .NET Framework 3.5 SP1 or the .NET Framework 4. For more information about WIF in the .NET Framework 4.5, also known as WIF 4.5, see the Windows Identity Foundation documentation in the .NET Framework 4.5 Development Guide.]
Creates an IClaimsPrincipal object from the security context of the specified HTTP request. The client certificate, if present in the request, is optionally validated.
Namespace: Microsoft.IdentityModel.Claims
Assembly: Microsoft.IdentityModel (in Microsoft.IdentityModel.dll)
Usage
'Usage
Dim httpContext As HttpContext
Dim clientCertificateAuthenticationEnabled As Boolean
Dim returnValue As IClaimsPrincipal
returnValue = ClaimsPrincipal.CreateFromHttpContext(httpContext, clientCertificateAuthenticationEnabled)
Syntax
'Declaration
Public Shared Function CreateFromHttpContext ( _
httpContext As HttpContext, _
clientCertificateAuthenticationEnabled As Boolean _
) As IClaimsPrincipal
public static IClaimsPrincipal CreateFromHttpContext (
HttpContext httpContext,
bool clientCertificateAuthenticationEnabled
)
public:
static IClaimsPrincipal^ CreateFromHttpContext (
HttpContext^ httpContext,
bool clientCertificateAuthenticationEnabled
)
public static IClaimsPrincipal CreateFromHttpContext (
HttpContext httpContext,
boolean clientCertificateAuthenticationEnabled
)
public static function CreateFromHttpContext (
httpContext : HttpContext,
clientCertificateAuthenticationEnabled : boolean
) : IClaimsPrincipal
Parameters
- httpContext
An HttpContext that represents the properties of the HTTP request.
- clientCertificateAuthenticationEnabled
true to indicate that the client certificate (if present) in the HttpContext must be authenticated.
Return Value
An IClaimsPrincipal appropriate for the token associated with the HTTP Request.
Exceptions
Exception type | Condition |
---|---|
ArgumentNullException | httpContext is null. |
Remarks
The IClaimsPrincipal is created from the System.Web.HttpContext.User property. The client certificate (if present) is optionally authenticated according to the value of the httpContext parameter. The method returns an IClaimsPrincipal implementation appropriate for the token associated with the request according to the following table.
User | Certificate | Returns |
---|---|---|
null |
No |
ClaimsPrincipal with an anonymous ClaimsIdentity. |
null |
Yes |
ClaimsPrincipal with a ClaimsPrincipalClaimsIdentity created from the certificate. |
Generic Principal |
No |
ClaimsPrincipal with an anonymous ClaimsIdentity. |
Generic Principal |
Yes |
ClaimsPrincipal with a ClaimsPrincipalClaimsIdentity created from the certificate. |
No |
||
Yes |
WindowsClaimsPrincipal with a WindowsClaimsIdentity and a ClaimsIdentity created from the certificate. |
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms
Target Platforms
Windows 7, Windows Server 2008 R2, Windows Vista SP2, Windows Server 2008 SP2, Windows Server 2003 SP2 (32-bit or 64-bit)
See Also
Reference
ClaimsPrincipal Class
ClaimsPrincipal Members
Microsoft.IdentityModel.Claims Namespace
Copyright © 2008 by Microsoft Corporation. All rights reserved.