当前位置: 首页>>代码示例>>C#>>正文


C# HttpActionContext.NotNull方法代码示例

本文整理汇总了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);
        }
开发者ID:c4rm4x,项目名称:C4rm4x.WebApi,代码行数:19,代码来源:DefaultCacheKeyGenerator.cs

示例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);
        }
开发者ID:c4rm4x,项目名称:C4rm4x.WebApi,代码行数:19,代码来源:OutputCacheAttribute.cs

示例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);
        }
开发者ID:c4rm4x,项目名称:C4rm4x.WebApi,代码行数:21,代码来源:SecuredAttribute.cs

示例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);
        }
开发者ID:c4rm4x,项目名称:C4rm4x.WebApi,代码行数:11,代码来源:SecuredAttribute.cs

示例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;
        }
开发者ID:c4rm4x,项目名称:C4rm4x.WebApi,代码行数:18,代码来源:SecuredAttribute.cs

示例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;
        }
开发者ID:c4rm4x,项目名称:C4rm4x.WebApi,代码行数:15,代码来源:SecuredAttribute.cs


注:本文中的System.Web.Http.Controllers.HttpActionContext.NotNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。