本文整理汇总了C#中System.Web.Routing.RequestContext.CurrentItem方法的典型用法代码示例。如果您正苦于以下问题:C# RequestContext.CurrentItem方法的具体用法?C# RequestContext.CurrentItem怎么用?C# RequestContext.CurrentItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Routing.RequestContext
的用法示例。
在下文中一共展示了RequestContext.CurrentItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryConvertContentToController
private bool TryConvertContentToController(RequestContext request, RouteValueDictionary values, string key, out ContentItem item)
{
if (!values.ContainsKey(key))
{
item = null;
return false;
}
object value = values[key];
item = value as ContentItem;
if (item == null && value is int)
{
item = engine.Persister.Get((int)value);
}
if (item == null || item == request.CurrentItem())
// got item from merged values
return false;
// replace requested controller when other "item" is passed
values.Remove(key);
values[ControllerKey] = controllerMapper.GetControllerName(item.GetContentType());
return true;
}
示例2: GetVirtualPath
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
ContentItem item;
Debug.WriteLine("GetVirtualPath for values: " + values.ToQueryString());
values = new RouteValueDictionary(values);
// try retrieving the item from the route values
if (!TryConvertContentToController(requestContext, values, ContentItemKey, out item))
{
// no item was passed, fallback to current content item
item = requestContext.CurrentItem();
if (item == null)
// no item = no play
return null;
if (!RequestedControllerMatchesItemController(values, item))
// someone's asking for a specific controller so we let another route handle it
return null;
}
if (item.IsPage)
return ResolveContentActionUrl(requestContext, values, item);
// try to find an appropriate page to use as path (part data goes into the query strings)
ContentItem page = values.CurrentItem<ContentItem>(ContentPageKey, engine.Persister);
if (page != null)
// a page parameter was passed
return ResolvePartActionUrl(requestContext, values, page, item);
page = requestContext.CurrentPage<ContentItem>();
if (page != null && page.IsPage)
// next use the current page
return ResolvePartActionUrl(requestContext, values, page, item);
page = item.ClosestPage();
if (page != null && page.IsPage)
// fallback to finding the closest page
return ResolvePartActionUrl(requestContext, values, page, item);
// can't find a page, don't link
return null;
}