RequireHttpsAttribute Class

An authorization filter that confirms requests are received over HTTPS.

Namespace
Microsoft.AspNetCore.Mvc
Assemblies
  • Microsoft.AspNetCore.Mvc.Core

Syntax

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class RequireHttpsAttribute : Attribute, _Attribute, IAuthorizationFilter, IOrderedFilter, IFilterMetadata
class Microsoft.AspNetCore.Mvc.RequireHttpsAttribute

Methods

HandleNonHttpsRequest(Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext)

Called from Microsoft.AspNetCore.Mvc.RequireHttpsAttribute.OnAuthorization(Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext) if the request is not received over HTTPS. Expectation is Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext.Result will not be <code>null</code> after this method returns.

Arguments:filterContext (Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext) – The Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext to update.
protected virtual void HandleNonHttpsRequest(AuthorizationFilterContext filterContext)
OnAuthorization(Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext)

Called early in the filter pipeline to confirm request is authorized. Confirms requests are received over HTTPS. Takes no action for HTTPS requests. Otherwise if it was a GET request, sets Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext.Result to a result which will redirect the client to the HTTPS version of the request URI. Otherwise, sets Microsoft.AspNetCore.Mvc.Filters.AuthorizationFilterContext.Result to a result which will set the status code to <code>403</code> (Forbidden).

public virtual void OnAuthorization(AuthorizationFilterContext filterContext)

Properties

Microsoft.AspNetCore.Mvc.RequireHttpsAttribute.Order
Return type:System.Int32
public int Order { get; set; }
Microsoft.AspNetCore.Mvc.RequireHttpsAttribute.Permanent

Specifies whether a permanent redirect, <code>301 Moved Permanently</code>, should be used instead of a temporary redirect, <code>302 Found</code>.

Return type:System.Boolean
public bool Permanent { get; set; }