本文整理汇总了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);
}