本文整理汇总了C#中Page.AsActual方法的典型用法代码示例。如果您正苦于以下问题:C# Page.AsActual方法的具体用法?C# Page.AsActual怎么用?C# Page.AsActual使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Page
的用法示例。
在下文中一共展示了Page.AsActual方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GeneratePageUrl
public static IHtmlString GeneratePageUrl(UrlHelper urlHelper, Site site, Page page, object values, FrontRequestChannel channel)
{
RouteValueDictionary routeValues = RouteValuesHelpers.GetRouteValues(values);
page = page.AsActual();
if (page == null)
{
return new HtmlString("");
}
if (page.Route != null && !string.IsNullOrEmpty(page.Route.ExternalUrl))
{
return new HtmlString(page.Route.ExternalUrl);
}
var pageRoute = page.Route.ToMvcRoute();
routeValues = RouteValuesHelpers.MergeRouteValues(pageRoute.Defaults, routeValues);
var routeVirtualPath = pageRoute.GetVirtualPath(urlHelper.RequestContext, routeValues);
if (routeVirtualPath == null)
{
throw new InvalidPageRouteException(page);
}
//string contentUrl = routeVirtualPath.VirtualPath;//don't decode the url. why??
//if do not decode the url, the route values contains Chinese character will cause bad request.
string contentUrl = HttpUtility.UrlDecode(routeVirtualPath.VirtualPath);
string pageUrl = contentUrl;
if (!string.IsNullOrEmpty(contentUrl) || (string.IsNullOrEmpty(pageUrl) && !page.IsDefault))
{
pageUrl = UrlUtility.Combine(page.VirtualPath, contentUrl);
}
if (string.IsNullOrEmpty(pageUrl))
{
pageUrl = urlHelper.Content("~/");
}
else
{
pageUrl = HttpUtility.UrlDecode(
urlHelper.RouteUrl("Page", new { PageUrl = new HtmlString(pageUrl) }));
}
var url = FrontUrlHelper.WrapperUrl(pageUrl, site, channel, page.RequireHttps);
return url;
}
示例2: GetViewsInPage
private IEnumerable<Models.View> GetViewsInPage(Site site, Page page)
{
var viewPositions = page.AsActual().PagePositions.Where(it => it is ViewPosition).OrderBy(it => it.Order);
foreach (ViewPosition viewPosition in viewPositions)
{
var view = new Models.View(site, viewPosition.ViewName).LastVersion();
if (!view.Exists())
{
throw new BscException(string.Format("The view '{0}' does not exists.Name.", view.Name));
}
yield return view;
}
}
示例3: Preview
public static IHtmlString Preview(UrlHelper urlHelper, Site site, Page page, object values)
{
if (page != null)
{
page = page.AsActual();
}
var pageUrl = urlHelper.Content("~/");
if (page != null && !page.IsDefault)
{
pageUrl = urlHelper.Content("~/" + page.VirtualPath);
}
var previewUrl = FrontUrlHelper.WrapperUrl(pageUrl, site, FrontRequestChannel.Unknown).ToString();
if (values != null)
{
RouteValueDictionary routeValues = new RouteValueDictionary(values);
foreach (var item in routeValues)
{
if (item.Value != null)
{
previewUrl = UrlUtility.AddQueryParam(previewUrl, item.Key, item.Value.ToString());
}
}
}
return new HtmlString(previewUrl);
}
示例4: PageRequestContext
/// <summary>
/// Initializes a new instance of the <see cref="PageRequestContext" /> class.
/// </summary>
/// <param name="controllerContext">The controller context.</param>
/// <param name="rawSite">The raw.</param>
/// <param name="site">The site.</param>
/// <param name="page">The page.</param>
/// <param name="requestChannel">The request channel.</param>
/// <param name="pageRequestUrl">The page request url with out page virtual path.</param>
public PageRequestContext(ControllerContext controllerContext, Site rawSite, Site site, Page rawPage, Page page,
FrontRequestChannel requestChannel, string pageRequestUrl)
{
RouteValues = new RouteValueDictionary();
this.ControllerContext = controllerContext;
var httpContext = HttpContext.Current;
this.RawSite = rawSite;
this.RawPage = rawPage;
this.Site = site.AsActual();
this.Page = page.AsActual();
this.RequestChannel = requestChannel;
this.AllQueryString = new NameValueCollection();
var queryString = httpContext.Request.QueryString;
foreach (var key in queryString.AllKeys)
{
var value = queryString[key];
if (!string.IsNullOrEmpty(value))
{
AllQueryString[HttpUtility.HtmlEncode(key)] = HttpUtility.HtmlEncode(value);
}
else
{
AllQueryString[HttpUtility.HtmlEncode(key)] = value;
}
}
if (string.IsNullOrEmpty(pageRequestUrl))
{
pageRequestUrl = "/";
}
HttpContextBase pageContext = new PageHttpContenxt(httpContext,
new PageHttpRequest(httpContext.Request, UrlUtility.Combine("~", pageRequestUrl), ""));
var routeData = page.Route.ToMvcRoute().GetRouteData(pageContext);
if (routeData != null)
{
RouteValues = routeData.Values;
//Combine page parameters to [QueryString].
foreach (var item in RouteValues)
{
if (item.Value != null)
{
AllQueryString[item.Key] = item.Value.ToString();
}
}
}
var moduleUrl = AllQueryString[ModuleUrlContext.ModuleUrlSegment];
var modulePositions = page.PagePositions.Where(it => it is ModulePosition || it is ProxyPosition).Count();
ModuleUrlContext = new ModuleUrlContext(this, moduleUrl, modulePositions);
}