Exemplo n.º 1
0
        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 = Kooboo.Web.Url.UrlUtility.AddQueryParam(previewUrl, item.Key, item.Value.ToString());
                    }
                }
            }
            return(new HtmlString(previewUrl));
        }
Exemplo n.º 2
0
        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 = Kooboo.Web.Url.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);
        }
Exemplo n.º 3
0
 public virtual IHtmlString WrapperUrl(string url, bool?requireSSL)
 {
     return(FrontUrlHelper.WrapperUrl(url, this.Site, this.RequestChannel, requireSSL));
 }
Exemplo n.º 4
0
 public virtual IHtmlString WrapperUrl(string url)
 {
     return(FrontUrlHelper.WrapperUrl(url, this.Site, this.RequestChannel, null));
 }