本文整理汇总了C#中System.Web.Http.Controllers.HttpActionContext.NotNull方法的典型用法代码示例。如果您正苦于以下问题:C# HttpActionContext.NotNull方法的具体用法?C# HttpActionContext.NotNull怎么用?C# HttpActionContext.NotNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.Controllers.HttpActionContext
的用法示例。
在下文中一共展示了HttpActionContext.NotNull方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
/// <summary>
/// Generates the key that should be used to cache/retrieve the content
/// for the given action context and action name
/// </summary>
/// <param name="actionContext">The action context</param>
/// <param name="actionName">The action name</param>
/// <returns>The key for the given action context and action name</returns>
public virtual string Generate(
HttpActionContext actionContext,
string actionName)
{
actionContext.NotNull(nameof(actionContext));
actionName.NotNullOrEmpty(nameof(actionName));
return Generate(
actionContext.ControllerContext.ControllerDescriptor.ControllerType,
actionName,
actionContext);
}
示例2: OnActionExecuting
/// <summary>
/// Action to occur before the actual action method is invoked
/// </summary>
/// <param name="actionContext">The action context</param>
public override void OnActionExecuting(
HttpActionContext actionContext)
{
actionContext.NotNull(nameof(actionContext));
if (!IsCachingAllowed(actionContext)) return;
var content = GetCachedContent(actionContext);
if (content.IsNullOrEmpty()) return;
CreateResponse(actionContext, content);
ApplyCacheHeaders(actionContext.Response);
}
示例3: OnAuthorization
/// <summary>
/// Called when an action is being authorized.
/// Authorization is denied if
/// - the request is not associated with any user
/// - the user is not authenticated,
/// - the user is authenticated but it is not in the authorized role (if defined)
/// or the user does not have the authorized claim (if defined)
/// </summary>
/// <param name="actionContext">The context</param>
public override void OnAuthorization(HttpActionContext actionContext)
{
actionContext.NotNull(nameof(actionContext));
if (SkipAuthorization(actionContext))
return;
if (!IsAuthenticated(actionContext))
HandleUnauthenticatedRequest(actionContext);
else if (!IsAuthorized(actionContext))
HandleUnauthorizedRequest(actionContext);
}
示例4: HandleUnauthorizedRequest
/// <summary>
/// Processes requests that fail authorization.
/// This default implementation creates a new response with the Forbidden status code.
/// </summary>
/// <param name="actionContext">The context</param>
protected virtual void HandleUnauthorizedRequest(HttpActionContext actionContext)
{
actionContext.NotNull(nameof(actionContext));
actionContext.Response = new HttpResponseMessage(HttpStatusCode.Forbidden);
}
示例5: IsAuthorized
/// <summary>
/// Determines whether access for this particular request is authorized.
/// Authorization is denied when the user is not in the authorized role (if defined)
/// or does not have the authorized claim (if defined)
/// </summary>
/// <param name="actionContext">The context</param>
/// <returns>true if access is authorized; otherwise false</returns>
protected virtual bool IsAuthorized(HttpActionContext actionContext)
{
actionContext.NotNull(nameof(actionContext));
var user = actionContext.ControllerContext.RequestContext.Principal;
if (NotAuthorizedRole(user) || NotAuthorizedClaim(user as ClaimsPrincipal))
return false;
return true;
}
示例6: IsAuthenticated
/// <summary>
/// Determines whether access for this particular request is authenticated.
/// </summary>
/// <param name="actionContext">The context</param>
/// <returns>true if access is authorized; otherwise false</returns>
protected virtual bool IsAuthenticated(HttpActionContext actionContext)
{
actionContext.NotNull(nameof(actionContext));
var user = actionContext.ControllerContext.RequestContext.Principal;
return user.IsNotNull() &&
user.Identity.IsNotNull() &&
user.Identity.IsAuthenticated;
}