public PageDefaultRouteViewModel DefaultRoute(ApiCall call) { PageDefaultRouteViewModel model = new PageDefaultRouteViewModel(); var startpages = call.WebSite.StartPages(); if (startpages != null && startpages.Count() > 0) { model.StartPage = startpages.First().Id; } var pagenotfound = WebSiteService.GetCustomErrorUrl(call.WebSite, 404); Guid PageNotFoundId = default(Guid); if (!string.IsNullOrEmpty(pagenotfound)) { if (!Guid.TryParse(pagenotfound, out PageNotFoundId)) { var DbPageNotFound = call.WebSite.SiteDb().Pages.GetByUrl(pagenotfound); if (DbPageNotFound != null) { PageNotFoundId = DbPageNotFound.Id; } } } var pageerror = WebSiteService.GetCustomErrorUrl(call.WebSite, 500); Guid PageErrorId = default(Guid); if (!string.IsNullOrEmpty(pageerror)) { if (!Guid.TryParse(pageerror, out PageErrorId)) { var DbPageError = call.WebSite.SiteDb().Pages.GetByUrl(pageerror); if (DbPageError != null) { PageErrorId = DbPageError.Id; } } } model.NotFound = PageNotFoundId; model.Error = PageErrorId; return(model); }
public async Task ExecuteKooboo(FrontContext frontContext) { DateTime endtime = default(DateTime); if (!frontContext.WebSite.Published && frontContext.RenderContext.Request.Channel == Data.Context.RequestChannel.Default) { if ((frontContext.Route != null && frontContext.Route.DestinationConstType == ConstObjectType.Page) || frontContext.RenderContext.User == null) { frontContext.RenderContext.Response.Body = System.Text.Encoding.UTF8.GetBytes("WebSite set to offline"); frontContext.RenderContext.Response.StatusCode = 503; return; } } if (frontContext.RenderContext.Response.StatusCode == 200) { try { await RouteRenderers.RenderAsync(frontContext); endtime = DateTime.UtcNow; // check for rights... CheckUserBandwidth(frontContext); } catch (Exception ex) { Kooboo.Data.Log.Instance.Exception.Write(frontContext.RenderContext.WebSite.Name + " " + frontContext.RenderContext.Request.Url); Kooboo.Data.Log.Instance.Exception.WriteException(ex); frontContext.RenderContext.Response.StatusCode = 500; var errorbody = await WebSiteService.RenderCustomError(frontContext, 500); if (!string.IsNullOrWhiteSpace(errorbody)) { frontContext.RenderContext.Response.Body = System.Text.Encoding.UTF8.GetBytes(errorbody); } frontContext.Log.AddEntry("500", ex.Message, DateTime.UtcNow, DateTime.UtcNow, 500, ex.Message); } } if (frontContext.RenderContext.Response.StatusCode != 200) { if (string.IsNullOrEmpty(frontContext.RenderContext.Response.RedirectLocation)) { var custom = frontContext.RenderContext.GetItem <CustomStatusCode>(); if (custom == null) { frontContext.RenderContext.Response.RedirectLocation = WebSiteService.GetCustomErrorUrl(frontContext.WebSite, frontContext.RenderContext.Response.StatusCode); } } } if (frontContext.WebSite.EnableVisitorLog && frontContext.RenderContext.Request.Channel == Data.Context.RequestChannel.Default) { if (frontContext.Page != null) { string referer = frontContext.RenderContext.Request.Headers.Get("Referer"); if (!string.IsNullOrEmpty(referer)) { frontContext.Log.Referer = referer; } frontContext.Log.Url = frontContext.RenderContext.Request.RawRelativeUrl; frontContext.Log.UserAgent = frontContext.RenderContext.Request.Headers.Get("User-Agent"); frontContext.Log.ClientIP = frontContext.RenderContext.Request.IP; frontContext.Log.Begin = frontContext.StartTime; if (endtime == default(DateTime)) { endtime = DateTime.UtcNow; } frontContext.Log.End = endtime; frontContext.Log.TimeSpan = (endtime - frontContext.StartTime).TotalMilliseconds; frontContext.Log.StatusCode = Convert.ToInt16(frontContext.RenderContext.Response.StatusCode); frontContext.Log.ObjectId = frontContext.Route != null ? frontContext.Route.objectId : default(Guid); if (frontContext.RenderContext.Response.Body != null) { frontContext.Log.Size = frontContext.RenderContext.Response.Body.Length; } frontContext.SiteDb.VisitorLog.Add(frontContext.Log); } if (frontContext.RenderContext.Response.StatusCode != 200) { var log = new Data.Models.SiteErrorLog(); log.ClientIP = frontContext.RenderContext.Request.IP; log.Url = frontContext.RenderContext.Request.RawRelativeUrl; log.StatusCode = frontContext.RenderContext.Response.StatusCode; frontContext.SiteDb.ErrorLog.Add(log); } } }