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


C# ResultExecutingContext.GetWorkContext方法代码示例

本文整理汇总了C#中System.Web.Mvc.ResultExecutingContext.GetWorkContext方法的典型用法代码示例。如果您正苦于以下问题:C# ResultExecutingContext.GetWorkContext方法的具体用法?C# ResultExecutingContext.GetWorkContext怎么用?C# ResultExecutingContext.GetWorkContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.ResultExecutingContext的用法示例。


在下文中一共展示了ResultExecutingContext.GetWorkContext方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnResultExecuting

        public void OnResultExecuting(ResultExecutingContext filterContext) {
            // Splash screen itself is not subject to filtering
            var routeValues = filterContext.RouteData.Values;
            if (routeValues["area"] as string == "Vandelay.Industries" &&
                routeValues["controller"] as string == "SplashScreen") {
                return;
            }

            // Neither are requests to the account controller
            if (routeValues["area"] as string == "Orchard.Users" &&
                routeValues["controller"] as string == "Account") {
                return;
            }

            var httpContext = filterContext.HttpContext;
            if (httpContext == null || httpContext.Request == null) return;

            // don't try to put a splash screen on POST requests
            if (httpContext.Request.HttpMethod.Equals("POST", StringComparison.OrdinalIgnoreCase)) return;

            // Don't put a splash screen on admin, media, or theme resources
            var requestedPath = httpContext.Request.AppRelativeCurrentExecutionFilePath;
            if (requestedPath.StartsWith("~/media/", StringComparison.OrdinalIgnoreCase)) return;
            if (requestedPath.StartsWith("~/themes/", StringComparison.OrdinalIgnoreCase)) return;
            if (AdminFilter.IsApplied(new RequestContext(httpContext, new RouteData()))) return;

            // ignore child actions, e.g. HomeController is using RenderAction()
            if (filterContext.IsChildAction) return;

            var splashScreenCookie = httpContext.Request
                .Cookies[SplashScreenSettingsPart.CookieName];
            // If cookie exists, the user has been here and has accepted the terms of use.
            if (splashScreenCookie != null && !String.IsNullOrWhiteSpace(splashScreenCookie.Value)) return;
            var config = filterContext.GetWorkContext().CurrentSite.As<SplashScreenSettingsPart>();
            if (config == null || !config.Enabled) return;

            // If request is for an ignored URL, don't display a splash screen
            var ignoredUrls = config.IgnoredUrls;
            if (IsIgnoredUrl(httpContext.Request.AppRelativeCurrentExecutionFilePath, ignoredUrls)) return;

            // This is a new user, and the splash screen is enabled. Redirect to splash screen.
            filterContext.Cancel = true;
            filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary {
                {"area", "Vandelay.Industries"},
                {"controller", "SplashScreen"},
                {"action", "Index"},
                {"returnUrl", httpContext.Request.Path}
            });
            filterContext.Result.ExecuteResult(filterContext.Controller.ControllerContext);
        }
开发者ID:hqmirror,项目名称:Vandelay.Industries,代码行数:50,代码来源:SplashScreenFilter.cs


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