/// <summary> /// The theme file url of site /// </summary> /// <param name="frontUrlHelper">The front url helper</param> /// <param name="site">The site</param> /// <param name="baseUri">Base uri</param> /// <param name="relativeThemeFilePath">The relative theme file path of site</param> /// <returns></returns> public static IHtmlString ThemeFileUrl(this FrontUrlHelper frontUrlHelper, Site site, string baseUri, string relativeThemeFilePath) { string resourceDomain = site.ResourceDomain; bool themeFileExists = false; string themeFileUrl = String.Empty; string themeFilePhysicalPath = String.Empty; do { site = site.AsActual(); Theme theme = new Theme(site, site.Theme).LastVersion(); themeFileUrl = UrlUtility.Combine(theme.VirtualPath, relativeThemeFilePath); themeFilePhysicalPath = HttpContext.Current.Server.MapPath(themeFileUrl); themeFileExists = File.Exists(themeFilePhysicalPath); site = theme.Site.Parent; } while (site != null && !themeFileExists); if (!String.IsNullOrEmpty(resourceDomain)) { baseUri = resourceDomain; // CDN have high priority } return(new HtmlString(UrlUtility.ToHttpAbsolute(baseUri, themeFileUrl))); }
/// <summary> /// The appointed theme file url of site /// </summary> /// <param name="frontUrlHelper">The front url helper</param> /// <param name="themeName">the theme</param> /// <param name="relativeUrl">The relative theme file path of site</param> /// <returns></returns> public static IHtmlString ThemeFileUrl(this FrontUrlHelper frontUrlHelper, string baseUri, string themeName, string relativeUrl) { var site = Site.Current; string resourceDomain = site.ResourceDomain; IHtmlString url = new HtmlString(""); if (!string.IsNullOrEmpty(themeName)) { var fileExists = false; var themeFileUrl = ""; do { site = site.AsActual(); Theme theme = new Theme(site, themeName).LastVersion(); themeFileUrl = Kooboo.Web.Url.UrlUtility.Combine(theme.VirtualPath, relativeUrl); var physicalPath = HttpContext.Current.Server.MapPath(themeFileUrl); fileExists = File.Exists(physicalPath); site = theme.Site.Parent; } while (site != null && !fileExists); if (!string.IsNullOrEmpty(resourceDomain)) { baseUri = resourceDomain; } return(new HtmlString(UrlUtility.ToHttpAbsolute(baseUri, themeFileUrl))); } return(frontUrlHelper.ThemeFileUrl(baseUri, relativeUrl)); }
public static IHtmlString SiteScriptsUrl(this FrontUrlHelper frontUrlHelper, Site site, string baseUri) { string url = Page_Context.Current.Url.Action("Scripts", "Resource", new { siteName = site.FullName, version = site.Version, area = String.Empty }); string wrapperUrl = FrontUrlHelper.WrapperUrl(url, site, FrontRequestChannel.Debug).ToString(); return(new HtmlString(UrlUtility.ToHttpAbsolute(baseUri, wrapperUrl))); }
public static ActionResult CreateRedirectResult(Site site, FrontRequestChannel channel, string url, string rawUrl, int?statusCode, RedirectType redirectType) { var redirectUrl = url; if (!UrlUtility.IsAbsoluteUrl(redirectUrl)) { redirectUrl = UrlUtility.ResolveUrl(redirectUrl); //WrapperUrl will cause endless loop if site host by ASP.NET development server when transfer redirect. if (redirectType != RedirectType.Transfer || Settings.IsHostByIIS) { redirectUrl = FrontUrlHelper.WrapperUrl(redirectUrl, site, channel).ToString(); } } if (!string.IsNullOrEmpty(rawUrl)) { redirectUrl = redirectUrl.AddQueryParam("errorpath", rawUrl); } if (statusCode != null) { redirectUrl = redirectUrl.AddQueryParam("statusCode", statusCode.ToString()); } switch (redirectType) { case RedirectType.Moved_Permanently_301: return(new Redirect301Result(redirectUrl)); case RedirectType.Transfer: return(new TransferResult(redirectUrl, statusCode ?? 200)); case RedirectType.Found_Redirect_302: default: return(new RedirectResult(redirectUrl)); } }
/// <summary> /// The script file url o fsite /// </summary> /// <param name="frontUrlHelper">The front url helper</param> /// <param name="site">The site</param> /// <param name="baseUri">Base uri</param> /// <param name="relativeScriptFilePath">The relative script file path of site</param> /// <returns></returns> public static IHtmlString ScriptFileUrl(this FrontUrlHelper frontUrlHelper, Site site, string baseUri, string relativeScriptFilePath, bool forceSSL = false) { string resourceDomain = site.ResourceDomain.FormatUrlWithProtocol(forceSSL); bool scriptFileExists = false; string scriptFileUrl = String.Empty; string scriptFilePhysicalPath = String.Empty; do { site = site.AsActual(); ScriptFile scriptFile = new ScriptFile(site, String.Empty); if (scriptFile != null) { scriptFileUrl = UrlUtility.Combine(scriptFile.VirtualPath, relativeScriptFilePath); scriptFilePhysicalPath = HttpContext.Current.Server.MapPath(scriptFileUrl); scriptFileExists = File.Exists(scriptFilePhysicalPath); } site = site.Parent; } while (site != null && !scriptFileExists); if (!String.IsNullOrEmpty(resourceDomain)) { baseUri = resourceDomain; // CDN have high priority } return(new HtmlString(UrlUtility.ToHttpAbsolute(baseUri, scriptFileUrl))); }
public static string GetAbsolutePageUrl(Site site, string pageUrl) { FrontRequestChannel requestChannel = site.FrontRequestChannel(); string wrapperPageUrl = FrontUrlHelper.WrapperUrl(pageUrl, site, requestChannel).ToString(); string host = GetHost(site); return(HttpContext.Current.Request.ToAbsoluteUrl(host, wrapperPageUrl)); }
public static bool IsCurrent(this Menu menu) { var currentUrl = HttpContext.Current.Request.Url.AbsolutePath; var urlHelper = new FrontUrlHelper(FrontContext.Current); var menuUrl = urlHelper.GetClientUrl(menu.Url); return(menuUrl.Equals(currentUrl, StringComparison.OrdinalIgnoreCase)); }
public static string GetAbsolutePageUrl(Site site, Page page, object values) { UrlHelper urlHelper = MvcUtility.GetUrlHelper(); FrontRequestChannel requestChannel = site.FrontRequestChannel(); string pageUrl = FrontUrlHelper.GeneratePageUrl(urlHelper, site, page, values, requestChannel).ToString(); string host = GetHost(site); return(HttpContext.Current.Request.ToAbsoluteUrl(host, pageUrl)); }
public override ActionResult Edit(Page newModel, string old_key) { JsonResultEntry result = new JsonResultEntry(); try { newModel.Site = Site; newModel.UserName = User.Identity.Name; var old = Manager.Get(Site, old_key); SavePosition(newModel); var saveAsDraft = this.Request.Form["SaveAsDraft"]; result.RedirectUrl = GetReturnUrl(); if (!string.IsNullOrEmpty(saveAsDraft) && saveAsDraft.ToLower() == "true") { Manager.PageProvider.SaveAsDraft(newModel); result.Model = new { preview = true }; //result.RedirectUrl = Url.Action("Draft", ControllerContext.RequestContext.AllRouteValues()); } else { var setPublished = Request.Form["SetPublished"]; if (!string.IsNullOrEmpty(setPublished)) { var published = false; bool.TryParse(setPublished, out published); newModel.Published = published; } else { result.RedirectUrl = null; result.AddMessage("The item has been saved.".Localize()); } Manager.Update(Site, newModel, old); } if (string.IsNullOrEmpty(result.RedirectUrl)) { result.Model = FrontUrlHelper.Preview(Url, Kooboo.CMS.Sites.Models.Site.Current, newModel, null).ToString(); } } catch (Exception e) { result.AddException(e); } return(Json(result)); }
public override IHtmlString RenderItemColumn(System.Web.Mvc.ViewContext viewContext) { var isStaticPage = Kooboo.CMS.Sites.Services.ServiceFactory.PageManager.IsStaticPage(Kooboo.CMS.Sites.Models.Site.Current, (Page)DataItem); UrlHelper urlHelper = new UrlHelper(viewContext.RequestContext); var href = FrontUrlHelper.Preview(urlHelper, Kooboo.CMS.Sites.Models.Site.Current, (Page)DataItem, null); if (!isStaticPage) { return(new HtmlString(PropertyValue == null ? "" : PropertyValue.ToString())); } return(new HtmlString(string.Format(@"<a href=""{0}"" target=""_blank"" class=""o-icon preview"" title=""{2}"">{1}</a>", href, PropertyValue, PropertyValue))); }
public IHtmlString Render(object dataItem, object value, ViewContext viewContext) { var isStaticPage = Kooboo.CMS.Sites.Services.ServiceFactory.PageManager.IsStaticPage(Kooboo.CMS.Sites.Models.Site.Current, (Page)dataItem); UrlHelper urlHelper = new UrlHelper(viewContext.RequestContext); var href = FrontUrlHelper.Preview(urlHelper, Kooboo.CMS.Sites.Models.Site.Current, (Page)dataItem, null); if (!isStaticPage) { return(new HtmlString("")); } return(new HtmlString(string.Format(@"<a href=""{0}"" target=""_blank"" class=""o-icon preview"" title=""{2}"">{1}</a>", href, "Preview".Localize(), "Preview".Localize()))); }
protected virtual void HandleUnauthorizedRequest(ActionExecutingContext filterContext) { var permission = Page_Context.Current.PageRequestContext.Page.Permission; if (permission != null && !string.IsNullOrEmpty(permission.UnauthorizedUrl)) { var unauthorizedUrl = permission.UnauthorizedUrl.AddQueryParam("returnUrl", filterContext.HttpContext.Request.RawUrl); var redirectUrl = FrontUrlHelper.WrapperUrl(unauthorizedUrl.TrimStart('~'), Page_Context.Current.PageRequestContext.Site, Page_Context.Current.PageRequestContext.RequestChannel); filterContext.Result = new RedirectResult(redirectUrl.ToString()); } else { throw new HttpException((int)HttpStatusCode.Unauthorized, "The page available for member only."); } }
public override void InitHelpers() { base.InitHelpers(); var context = FrontContext.Current; if (context != null) { CurrentSite = context.Site; CurrentPage = context.Page; DataContext = context.DataContext; FrontHtml = new FrontHtmlHelper(Html, context); FrontUrl = new FrontUrlHelper(context); } FrontController = ViewContext.Controller as FrontControllerBase; Validation = new SusuCMS.Web.Front.Validation.ValidationHelper(ViewContext.HttpContext, ViewData.ModelState); }
protected virtual Site MatchSiteByVisitRule(Site site) { ABSiteSetting abSiteSetting = null; var httpContext = new HttpContextWrapper(HttpContext.Current); var matchedSite = Kooboo.CMS.Common.Runtime.EngineContext.Current.Resolve <Kooboo.CMS.Sites.Services.ABSiteSettingManager>().MatchRule(site, httpContext, out abSiteSetting); if (matchedSite != site && abSiteSetting != null && abSiteSetting.RedirectType != null && abSiteSetting.RedirectType.Value != RedirectType.Transfer) { string url = null; var rawUrl = RequestUrl; if (!string.IsNullOrEmpty(httpContext.Request.Url.Query)) { rawUrl = rawUrl + httpContext.Request.Url.Query; } if (this.RequestChannel == FrontRequestChannel.Debug) { url = FrontUrlHelper.WrapperUrl(rawUrl, matchedSite, FrontRequestChannel.Debug).ToString(); } else { var domain = matchedSite.FullDomains.FirstOrDefault(); if (!string.IsNullOrEmpty(domain)) { var baseUri = httpContext.Request.Url.Scheme + "://" + domain; url = new Uri(new Uri(baseUri), rawUrl).ToString(); } } if (!string.IsNullOrEmpty(url)) { if (abSiteSetting.RedirectType.Value == RedirectType.Found_Redirect_302) { httpContext.Response.Redirect(url); } else if (abSiteSetting.RedirectType.Value == RedirectType.Moved_Permanently_301) { httpContext.Response.RedirectPermanent(url); } } } return(matchedSite); }
/// <summary> /// The script file url of current site /// </summary> /// <param name="frontUrlHelper">The front url helper</param> /// <param name="relativeScriptFilePath">The relative script file path of current site</param> /// <returns></returns> public static IHtmlString ScriptFileUrl(this FrontUrlHelper frontUrlHelper, string relativeScriptFilePath) { Site site = Site.Current; return(ScriptFileUrl(frontUrlHelper, site, relativeScriptFilePath)); }
/// <summary> /// The theme file url of current site /// </summary> /// <param name="frontUrlHelper">The front url helper</param> /// <param name="baseUri">Base uri</param> /// <param name="relativeThemeFilePath">The relative theme file path of current site</param> /// <returns></returns> public static IHtmlString ThemeFileUrl(this FrontUrlHelper frontUrlHelper, string baseUri, string relativeThemeFilePath) { Site site = Site.Current; return(ThemeFileUrl(frontUrlHelper, site, baseUri, relativeThemeFilePath)); }
/// <summary> /// The script file url of current site /// </summary> /// <param name="frontUrlHelper">The front url helper</param> /// <param name="baseUri">Base uri</param> /// <param name="relativeScriptFilePath">The relative script file path of current site</param> /// <returns></returns> public static IHtmlString ScriptFileUrl(this FrontUrlHelper frontUrlHelper, string baseUri, string relativeScriptFilePath, bool forceSSL = false) { Site site = Site.Current; return(ScriptFileUrl(frontUrlHelper, site, baseUri, relativeScriptFilePath, forceSSL)); }
/// <summary> /// The script file url of site /// </summary> /// <param name="frontUrlHelper">The front url helper</param> /// <param name="site">The site</param> /// <param name="relativeScriptFilePath">The relative script file path of site</param> /// <returns></returns> public static IHtmlString ScriptFileUrl(this FrontUrlHelper frontUrlHelper, Site site, string relativeScriptFilePath) { return(ScriptFileUrl(frontUrlHelper, site, site.ResourceDomain, relativeScriptFilePath)); }
public static IHtmlString SiteScriptsUrl(this FrontUrlHelper frontUrlHelper, Site site) { return(SiteScriptsUrl(frontUrlHelper, site, site.ResourceDomain)); }