本文整理汇总了C#中System.Web.Routing.RouteData.ApplyCurrentItem方法的典型用法代码示例。如果您正苦于以下问题:C# RouteData.ApplyCurrentItem方法的具体用法?C# RouteData.ApplyCurrentItem怎么用?C# RouteData.ApplyCurrentItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Routing.RouteData
的用法示例。
在下文中一共展示了RouteData.ApplyCurrentItem方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AnalyzeView
private ViewTemplateDescription AnalyzeView(HttpContextBase httpContext, VirtualFile file, string controllerName, Type modelType)
{
if (modelType == null || !typeof(ContentItem).IsAssignableFrom(modelType) || modelType.IsAbstract)
return null;
var model = Activator.CreateInstance(modelType) as ContentItem;
var rd = new RouteData();
bool isPage = model.IsPage;
rd.ApplyCurrentItem(controllerName, Path.GetFileNameWithoutExtension(file.Name), isPage ? model : new StubItem(), isPage ? null : model);
var cctx = new ControllerContext(httpContext, rd, new StubController());
var result = isPage
? viewEnginesProvider.Get().FindView(cctx, file.VirtualPath, null)
: viewEnginesProvider.Get().FindPartialView(cctx, file.VirtualPath);
if (result.View == null)
return null;
return RenderViewForRegistration(file, modelType, cctx, result);
}
示例2: CreateHtmlHelper
private static HtmlHelper CreateHtmlHelper(ContentItem item, TextWriter writer)
{
var httpContext = new HttpContextWrapper(HttpContext.Current);
var routeData = new RouteData();
routeData.ApplyCurrentItem("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);
}
示例3: GetRouteDataForPath
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;
string hostAndRawUrl = String.Format("{0}://{1}{2}", request.Url.Scheme, host, Url.ToAbsolute(request.AppRelativeCurrentExecutionFilePath));
PathData td = engine.UrlParser.ResolvePath(hostAndRawUrl);
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;
data.ApplyCurrentItem(controllerName, actionName, page, part);
data.DataTokens[ContentEngineKey] = engine;
return data;
}
示例4: CreateRouteData
private RouteData CreateRouteData()
{
ContentItem page = item;
var ic = Page as IItemContainer;
if (ic != null)
page = ic.CurrentItem;
var rd = new RouteData();
rd.ApplyCurrentItem("webform", "Index", page, item);
return rd;
}
示例5: GetRouteData
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.ApplyCurrentItem(item.ClosestPage(), item);
return data;
}