private void CheckInstallation()
        {
            string currentUrl = webContext.ToAppRelative(webContext.Url.LocalUrl);
            bool   isEditing  = currentUrl.StartsWith(webContext.ToAppRelative(managementUrl), StringComparison.InvariantCultureIgnoreCase);

            if (isEditing)
            {
                return;
            }

            DatabaseStatus status      = installer.GetStatus();
            Url            redirectUrl = Url.ResolveTokens(welcomeUrl);

            if (status.NeedsUpgrade)
            {
                redirectUrl = redirectUrl.AppendQuery("action", "upgrade");
            }
            else if (!status.IsInstalled)
            {
                redirectUrl = redirectUrl.AppendQuery("action", "install");
            }
            else if (status.NeedsRebase)
            {
                redirectUrl = redirectUrl.AppendQuery("action", "rebase");
            }
            else
            {
                return;
            }
            Trace.WriteLine("Redirecting to '" + redirectUrl + "' to handle status: " + status.ToStatusString());
            webContext.Response.Redirect(redirectUrl);
        }
        private void CheckInstallation()
        {
            string currentUrl = Url.ToRelative(webContext.Url.LocalUrl);

            try
            {
                AuthenticationSection authentication = ConfigurationManager.GetSection("system.web/authentication") as AuthenticationSection;
                if (currentUrl.StartsWith(Url.ToAbsolute(authentication.Forms.LoginUrl), StringComparison.InvariantCultureIgnoreCase))
                {
                    // don't redirect from login page
                    return;
                }
            }
            catch (Exception ex)
            {
                Trace.TraceWarning(ex.ToString());
            }
            var status = this.status;

            Url redirectUrl = Url.ResolveTokens(welcomeUrl);

            if (status == null)
            {
                Trace.TraceWarning("Null status");
                installer.UpdateStatus(SystemStatusLevel.Unknown);
                return;
            }
            else if (status.NeedsUpgrade)
            {
                redirectUrl = redirectUrl.AppendQuery("action", "upgrade");
            }
            else if (!status.IsInstalled)
            {
                redirectUrl = redirectUrl.AppendQuery("action", "install");
            }
            else if (status.NeedsRebase)
            {
                redirectUrl = redirectUrl.AppendQuery("action", "rebase");
            }
            else
            {
                this.status = null;
                installer.UpdateStatus(status.Level);
                this.broker.BeginRequest -= BeginRequest;
                return;
            }

            installer.UpdateStatus(status.Level);

            bool isEditing = currentUrl.StartsWith(N2.Web.Url.ToRelative(managementUrl), StringComparison.InvariantCultureIgnoreCase);

            if (isEditing)
            {
                return;
            }

            logger.Debug("Redirecting to '" + redirectUrl + "' to handle status: " + status.ToStatusString());

            this.status = null;
            webContext.HttpContext.Response.Redirect(redirectUrl);
        }