Ejemplo n.º 1
0
        public string RenderSystemLink(RenderContext context, Routing.Route route)
        {
            Render.FrontContext frontContext = context.GetItem <Render.FrontContext>();

            route.Parameters = ObjectRoute.ParseParameters(route, this.Url);

            var  constTypeString = route.Parameters.GetValue("objecttype");
            byte constType       = ConstObjectType.Unknown;

            if (!byte.TryParse(constTypeString, out constType))
            {
                constType = ConstTypeContainer.GetConstType(constTypeString);
            }
            var id = route.Parameters.GetValue("nameorid");

            if (constType == ConstObjectType.View)
            {
                var view = context.WebSite.SiteDb().Views.GetByNameOrId(id);

                if (view != null)
                {
                    var relation = context.WebSite.SiteDb().Relations.GetReferredBy(view, ConstObjectType.Page);

                    if (relation != null && relation.Count > 0)
                    {
                        var pageid = relation[0].objectXId;

                        var pageroute = context.WebSite.SiteDb().Routes.GetByObjectId(pageid);

                        if (pageroute != null)
                        {
                            return(RenderPageRoute(context, pageroute));
                        }
                    }
                    /// if view was not rendered within and by the page... try to render with rendercode.
                    if (frontContext.Page != null && frontContext.ExecutingView != null)
                    {
                        string currenturl = context.Request.RelativeUrl;

                        var values = PageRoute.GetViewParameterValues(context.WebSite.SiteDb(), view, frontContext);

                        var alternativeviewcode = Cache.ViewInSamePosition.GetAlternativeCode(frontContext.ExecutingView.Id, view.Id);

                        values.Add(SiteConstants.AlternativeViewQueryName, alternativeviewcode.ToString());
                        return(Kooboo.Lib.Helper.UrlHelper.AppendQueryString(currenturl, values));
                    }

                    else if (frontContext.Page == null)
                    {
                        var values = PageRoute.GetViewParameterValues(context.WebSite.SiteDb(), view, frontContext);

                        return(Kooboo.Lib.Helper.UrlHelper.AppendQueryString(this.Url, values));
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        public async Task Invoke(RenderContext context)
        {
            FrontContext kooboocontext = new FrontContext(context);

            if (context.WebSite != null)
            {
                if (!Kooboo.Web.Security.AccessControl.HasWebsiteAccess(context.WebSite, context))
                {
                    if (!CheckIsBackEndOrImageUrl(kooboocontext.RenderContext.Request.RelativeUrl))
                    {
                        if (context.User == null)
                        {
                            context.Response.Redirect(302, "/_admin/account/login?type=site&returnurl=" + System.Web.HttpUtility.UrlEncode(context.Request.RawRelativeUrl));
                            context.Response.End = true;
                            return;
                        }
                        else
                        {
                            context.Response.Redirect(302, Kooboo.DataConstants.Default403Page);
                            context.Response.End = true;
                            return;
                        }
                    }
                }


                if (kooboocontext.RenderContext.IsSiteBinding || !CheckIsBackEndOrImageUrl(kooboocontext.RenderContext.Request.RelativeUrl))
                {
                    ObjectRoute.Parse(kooboocontext);
                    if (kooboocontext.Route != null && kooboocontext.Route.objectId != default(Guid))
                    {
                        await ExecuteKooboo(kooboocontext);

                        return;
                    }
                }


                if (kooboocontext.Route == null && !String.IsNullOrEmpty(kooboocontext.WebSite.LocalRootPath))
                {
                    await Next.Invoke(context);

                    return;
                }

                if (!CheckIsBackEndOrImageUrl(kooboocontext.RenderContext.Request.RelativeUrl))
                {
                    if (kooboocontext.Route == null || kooboocontext.Route.objectId == default(Guid))
                    {
                        if (kooboocontext.SiteDb.WebSite.ContinueDownload)
                        {
                            if (Data.AppSettings.IsOnlineServer && !Kooboo.Web.Security.ActionControl.CanServerDownloadMorePages(kooboocontext.SiteDb, kooboocontext.RenderContext.Request.RelativeUrl))
                            {
                                kooboocontext.RenderContext.Response.StatusCode = 402;
                                var errorbody = await WebSiteService.RenderCustomError(kooboocontext, 402);

                                if (!string.IsNullOrWhiteSpace(errorbody))
                                {
                                    kooboocontext.RenderContext.Response.Body = System.Text.Encoding.UTF8.GetBytes(errorbody);
                                }
                                return;
                            }
                            else
                            {
                                var continuedownload = await TransferManager.continueDownload(kooboocontext.SiteDb, kooboocontext.RenderContext.Request.RawRelativeUrl);

                                if (continuedownload != null)
                                {
                                    ObjectRoute.Parse(kooboocontext);
                                }
                            }
                        }
                    }

                    if (kooboocontext.Route != null && kooboocontext.Route.objectId != default(Guid))
                    {
                        await ExecuteKooboo(kooboocontext);

                        return;
                    }
                    else
                    {
                        kooboocontext.RenderContext.Response.StatusCode = 404;
                        var errorbody = await WebSiteService.RenderCustomError(kooboocontext, 404);

                        if (!string.IsNullOrWhiteSpace(errorbody))
                        {
                            kooboocontext.RenderContext.Response.Body = System.Text.Encoding.UTF8.GetBytes(errorbody);
                        }
                        return;
                    }
                }
                else
                {
                    // reensure siteid... in case of the same url used for login.
                    var siteid = Kooboo.Data.Context.WebServerContext.RequestSiteId(context.Request);
                    if (siteid != kooboocontext.RenderContext.WebSite.Id)
                    {
                        var site = Kooboo.Data.GlobalDb.WebSites.Get(siteid);
                        if (site != null)
                        {
                            kooboocontext.WebSite = site;
                        }
                    }
                }
            }

            if (RenderThumbnail(kooboocontext))
            {
                return;
            }

            // access control for allow users...
            await Next.Invoke(context);
        }