private static HtmlHelper CreateHtmlHelper(ContentItem item, TextWriter writer) { var httpContext = new HttpContextWrapper(HttpContext.Current); var routeData = new RouteData(); RouteExtensions.ApplyCurrentPath(routeData, "WebForms", "Index", new PathData(item.ClosestPage(), item)); return new HtmlHelper( new ViewContext( new ControllerContext() { HttpContext = httpContext, RequestContext = new RequestContext(httpContext, routeData), RouteData = routeData }, new WebFormView(HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath), new ViewDataDictionary(), new TempDataDictionary(), writer), new ViewPage(), RouteTable.Routes); }
private static HtmlHelper CreateHtmlHelper(ContentItem item, TextWriter writer) { var httpContext = new HttpContextWrapper(HttpContext.Current); var routeData = new RouteData(); RouteExtensions.ApplyCurrentItem(routeData, "webforms", "index", item.ClosestPage(), item); return(new HtmlHelper( new ViewContext( new ControllerContext() { HttpContext = httpContext, RequestContext = new RequestContext(httpContext, routeData), RouteData = routeData }, new WebFormView(HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath), new ViewDataDictionary(), new TempDataDictionary(), writer), new ViewPage(), RouteTable.Routes)); }
private RouteData GetRouteData(RequestContext requestContext, ContentItem item, string controllerName) { var data = new RouteData(); data.Values[ContentRoute.ControllerKey] = controllerName; data.Values[ContentRoute.ActionKey] = "Index"; data.Values[ContentRoute.ContentItemKey] = item.ID; // retrieve the virtual path so we can figure out if this item is routed through an area var vpd = routes.GetVirtualPath(requestContext, data.Values); if (vpd == null) { throw new InvalidOperationException("Unable to render " + item + " (" + data.Values.ToQueryString() + " did not match any route)"); } data.Values["area"] = vpd.DataTokens["area"]; data.Route = vpd.Route; data.ApplyCurrentPath(new PathData(item.ClosestPage(), item)); return(data); }
private RouteData GetRouteDataForPath(HttpRequestBase request) { if (request == null) { throw new ArgumentNullException("request"); } if (request.Url == null) { throw new ArgumentException("Request has no URL", "request"); } //On a multi-lingual site with separate domains per language, //the full url (with host) should be passed to UrlParser.ResolvePath(): string host = (request.Url.IsDefaultPort) ? request.Url.Host : request.Url.Authority; var url = new Url(request.Url.Scheme, host, request.RawUrl); PathData path; var rpp = engine.Resolve <RequestPathProvider>(); if (rpp.IsRewritable(url) && rpp.IsObservable(url)) { path = rpp.ResolveUrl(url); } else { path = PathData.Empty; } if (!path.IsEmpty() && path.IsRewritable && StopRewritableItems) { return(new RouteData(this, new StopRoutingHandler())); } var page = path.CurrentPage; var actionName = path.Action; if (string.IsNullOrEmpty(actionName)) { actionName = request.QueryString["action"] ?? "Index"; } if (!string.IsNullOrEmpty(request.QueryString[PathData.PageQueryKey])) { int pageId; if (int.TryParse(request.QueryString[PathData.PageQueryKey], out pageId)) { path.CurrentPage = page = engine.Persister.Get(pageId); } } ContentItem part = null; if (!string.IsNullOrEmpty(request.QueryString[PathData.PartQueryKey])) { // part in query string is used to render a part int partId; if (int.TryParse(request.QueryString[PathData.PartQueryKey], out partId)) { path.CurrentItem = part = engine.Persister.Get(partId); path.Controller = null; } } else if (!string.IsNullOrEmpty(request.QueryString[PathData.ItemQueryKey])) { // this is a discrepancy between mvc and the legacy // in mvc the item query key doesn't route to the item, it's a marker // the urlparser however parses the item query key and passes the item as current in pathdata // hence this somewhat strange sidestepping int itemId; if (int.TryParse(request.QueryString[PathData.ItemQueryKey], out itemId)) { if (itemId == path.ID || (path.ID == 0 && path.CurrentItem != null && itemId == path.CurrentItem.VersionOf.ID)) { // we have an item id and it matches the path data we found via url parser // it hasn't been changed by a specific part query string so we reset it path.CurrentItem = path.CurrentPage; path.Controller = null; } } } if (page == null && part == null) { return(null); } path.CurrentPage = page ?? part.ClosestPage(); var controllerName = path.Controller ?? controllerMapper.GetControllerName((part ?? page).GetContentType()); if (controllerName == null) { return(null); } if (actionName == null || !controllerMapper.ControllerHasAction(controllerName, actionName)) { return(null); } var data = new RouteData(this, routeHandler); foreach (var defaultPair in innerRoute.Defaults) { data.Values[defaultPair.Key] = defaultPair.Value; } foreach (var tokenPair in innerRoute.DataTokens) { data.DataTokens[tokenPair.Key] = tokenPair.Value; } RouteExtensions.ApplyCurrentPath(data, controllerName, actionName, path); data.DataTokens[ContentEngineKey] = engine; return(data); }
private RouteData GetRouteDataForPath(HttpRequestBase request) { //On a multi-lingual site with separate domains per language, //the full url (with host) should be passed to UrlParser.ResolvePath(): string host = (request.Url.IsDefaultPort) ? request.Url.Host : request.Url.Authority; var url = new Url(request.Url.Scheme, host, request.AppRelativeCurrentExecutionFilePath); PathData td = engine.Resolve <RequestPathProvider>().ResolveUrl(url); var page = td.CurrentPage; var actionName = td.Action; if (string.IsNullOrEmpty(actionName)) { actionName = request.QueryString["action"] ?? "Index"; } if (!string.IsNullOrEmpty(request.QueryString[PathData.PageQueryKey])) { int pageId; if (int.TryParse(request.QueryString[PathData.PageQueryKey], out pageId)) { td.CurrentPage = page = engine.Persister.Get(pageId); } } ContentItem part = null; if (!string.IsNullOrEmpty(request.QueryString[PathData.PartQueryKey])) { // part in query string is used to render a part int partId; if (int.TryParse(request.QueryString[PathData.PartQueryKey], out partId)) { td.CurrentItem = part = engine.Persister.Get(partId); } } if (page == null && part == null) { return(null); } else if (page == null) { page = part.ClosestPage(); } var controllerName = controllerMapper.GetControllerName((part ?? page).GetContentType()); if (controllerName == null) { return(null); } if (actionName == null || !controllerMapper.ControllerHasAction(controllerName, actionName)) { return(null); } var data = new RouteData(this, routeHandler); foreach (var defaultPair in innerRoute.Defaults) { data.Values[defaultPair.Key] = defaultPair.Value; } foreach (var tokenPair in innerRoute.DataTokens) { data.DataTokens[tokenPair.Key] = tokenPair.Value; } RouteExtensions.ApplyCurrentItem(data, controllerName, actionName, page, part); data.DataTokens[ContentEngineKey] = engine; return(data); }
private RouteData GetRouteData(RequestContext requestContext, ContentItem item, string controllerName) { var data = new RouteData(); data.Values[ContentRoute.ControllerKey] = controllerName; data.Values[ContentRoute.ActionKey] = "Index"; data.Values[ContentRoute.ContentItemKey] = item.ID; // retrieve the virtual path so we can figure out if this item is routed through an area var vpd = routes.GetVirtualPath(requestContext, data.Values); if (vpd == null) throw new InvalidOperationException("Unable to render " + item + " (" + data.Values.ToQueryString() + " did not match any route)"); data.Values["area"] = vpd.DataTokens["area"]; data.Route = vpd.Route; data.ApplyCurrentPath(new PathData(item.ClosestPage(), item)); return data; }