示例#1
0
        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));
            }
        }
        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)));
        }
示例#3
0
        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));
        }
        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.");
            }
        }
示例#5
0
        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);
        }