示例#1
0
        // ensures Umbraco is ready to handle requests
        // if not, set status to 503 and transfer request, and return false
        // if yes, return true
        bool EnsureIsReady(HttpContextBase httpContext, Uri uri)
        {
            var ready = ApplicationContext.Current.IsReady;

            // ensure we are ready
            if (!ready)
            {
                LogHelper.Warn <UmbracoModule>("Umbraco is not ready");

                if (!UmbracoSettings.EnableSplashWhileLoading)
                {
                    // let requests pile up and wait for 10s then show the splash anyway
                    ready = ApplicationContext.Current.WaitForReady(10 * 1000);
                }

                if (!ready)
                {
                    httpContext.Response.StatusCode = 503;

                    var bootUrl = UmbracoSettings.BootSplashPage;
                    if (string.IsNullOrWhiteSpace(bootUrl))
                    {
                        bootUrl = "~/config/splashes/booting.aspx";
                    }
                    httpContext.RewritePath(UriUtility.ToAbsolute(bootUrl) + "?url=" + HttpUtility.UrlEncode(uri.ToString()));

                    return(false);
                }
            }

            return(true);
        }
示例#2
0
        private bool EnsureRuntime(HttpContextBase httpContext, Uri uri)
        {
            var level = _runtime.Level;

            switch (level)
            {
            // we should never handle Unknown nor Boot: the runtime boots in Application_Start
            // and as long as it has not booted, no request other than the initial request is
            // going to be served (see https://stackoverflow.com/a/21402100)
            // we should never handle BootFailed: if boot failed, the pipeline should not run
            // at all
            case RuntimeLevel.Unknown:
            case RuntimeLevel.Boot:
            case RuntimeLevel.BootFailed:
                throw new PanicException($"Unexpected runtime level: {level}.");

            case RuntimeLevel.Run:
                // ok
                return(true);

            case RuntimeLevel.Install:
            case RuntimeLevel.Upgrade:
                // redirect to install
                ReportRuntime(level, "Umbraco must install or upgrade.");
                var installPath = UriUtility.ToAbsolute(SystemDirectories.Install);
                var installUrl  = $"{installPath}/?redir=true&url={HttpUtility.UrlEncode(uri.ToString())}";
                httpContext.Response.Redirect(installUrl, true);
                return(false);    // cannot serve content

            default:
                throw new NotSupportedException($"Unexpected runtime level: {level}.");
            }
        }
        private bool EnsureRuntime(HttpContextBase httpContext, Uri uri)
        {
            var debug = _runtime.Debug;
            var level = _runtime.Level;

            switch (level)
            {
            case RuntimeLevel.Unknown:
            case RuntimeLevel.Boot:
                // not ready yet, but wait
                ReportRuntime(level, "Umbraco is booting.");

                // let requests pile up and wait for 10s then show the splash anyway
                if (Current.Configs.Settings().Content.EnableSplashWhileLoading == false &&
                    ((RuntimeState)_runtime).WaitForRunLevel(TimeSpan.FromSeconds(10)))
                {
                    return(true);
                }

                // redirect to booting page
                httpContext.Response.StatusCode = 503;                             // temp not available
                const string bootUrl = "~/config/splashes/booting.aspx";
                httpContext.Response.AddHeader("Retry-After", debug ? "1" : "30"); // seconds
                httpContext.RewritePath(UriUtility.ToAbsolute(bootUrl) + "?url=" + HttpUtility.UrlEncode(uri.ToString()));
                return(false);                                                     // cannot serve content

            case RuntimeLevel.BootFailed:
                // redirect to death page
                ReportRuntime(level, "Umbraco has failed.");

                httpContext.Response.StatusCode = 503;                              // temp not available
                const string deathUrl = "~/config/splashes/death.aspx";
                httpContext.Response.AddHeader("Retry-After", debug ? "1" : "300"); // seconds
                httpContext.RewritePath(UriUtility.ToAbsolute(deathUrl) + "?url=" + HttpUtility.UrlEncode(uri.ToString()));
                return(false);                                                      // cannot serve content

            case RuntimeLevel.Run:
                // ok
                return(true);

            case RuntimeLevel.Install:
            case RuntimeLevel.Upgrade:
                // redirect to install
                ReportRuntime(level, "Umbraco must install or upgrade.");
                var installPath = UriUtility.ToAbsolute(SystemDirectories.Install);
                var installUrl  = $"{installPath}/?redir=true&url={HttpUtility.UrlEncode(uri.ToString())}";
                httpContext.Response.Redirect(installUrl, true);
                return(false);    // cannot serve content

            default:
                throw new NotSupportedException($"Unexpected runtime level: {Current.RuntimeState.Level}.");
            }
        }
示例#4
0
        // ensures Umbraco is configured
        // if not, redirect to install and return false
        // if yes, return true
        bool EnsureIsConfigured(HttpContextBase httpContext, Uri uri)
        {
            if (!ApplicationContext.Current.IsConfigured)
            {
                LogHelper.Warn <UmbracoModule>("Umbraco is not configured");

                string installPath = UriUtility.ToAbsolute(SystemDirectories.Install);
                string installUrl  = string.Format("{0}/default.aspx?redir=true&url={1}", installPath, HttpUtility.UrlEncode(uri.ToString()));
                httpContext.Response.Redirect(installUrl, true);
                return(false);
            }
            return(true);
        }
示例#5
0
        // ensures Umbraco has at least one published node
        // if not, rewrites to splash and return false
        // if yes, return true
        private bool EnsureHasContent(UmbracoContext context, HttpContextBase httpContext)
        {
            if (context.Content.HasContent())
            {
                return(true);
            }

            _logger.Warn <UmbracoModule>("Umbraco has no content");

            const string noContentUrl = "~/config/splashes/noNodes.aspx";

            httpContext.RewritePath(UriUtility.ToAbsolute(noContentUrl));

            return(false);
        }
示例#6
0
        // ensures Umbraco has at least one published node
        // if not, rewrites to splash and return false
        // if yes, return true
        private static bool EnsureHasContent(UmbracoContext context, HttpContextBase httpContext)
        {
            if (context.ContentCache.HasContent())
            {
                return(true);
            }

            LogHelper.Warn <UmbracoModule>("Umbraco has no content");

            httpContext.Response.StatusCode = 503;

            const string noContentUrl = "~/config/splashes/noNodes.aspx";

            httpContext.RewritePath(UriUtility.ToAbsolute(noContentUrl));

            return(false);
        }
示例#7
0
        // ensures Umbraco has at least one published node
        // if not, rewrites to splash and return false
        // if yes, return true
        bool EnsureHasContent(UmbracoContext context, HttpContextBase httpContext)
        {
            var store = context.RoutingContext.PublishedContentStore;

            if (!store.HasContent(context))
            {
                LogHelper.Warn <UmbracoModule>("Umbraco has no content");

                httpContext.Response.StatusCode = 503;

                var noContentUrl = "~/config/splashes/noNodes.aspx";
                httpContext.RewritePath(UriUtility.ToAbsolute(noContentUrl));

                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#8
0
        // ensures Umbraco is configured
        // if not, redirect to install and return false
        // if yes, return true
        private bool EnsureIsConfigured(HttpContextBase httpContext, Uri uri)
        {
            if (ApplicationContext.Current.IsConfigured)
            {
                return(true);
            }

            if (_notConfiguredReported)
            {
                // remember it's been reported so we don't flood the log
                // no thread-safety so there may be a few log entries, doesn't matter
                _notConfiguredReported = true;
                LogHelper.Warn <UmbracoModule>("Umbraco is not configured");
            }

            var installPath = UriUtility.ToAbsolute(SystemDirectories.Install);
            var installUrl  = string.Format("{0}/?redir=true&url={1}", installPath, HttpUtility.UrlEncode(uri.ToString()));

            httpContext.Response.Redirect(installUrl, true);
            return(false);
        }