GetEmptyHome() static private method

static private GetEmptyHome ( ) : SiteNav
return SiteNav
        protected override IHttpHandler GetHttpHandler(System.Web.Routing.RequestContext requestCtx)
        {
            string requestedUri = (string)requestCtx.RouteData.Values["RequestedUri"];

            requestedUri = String.IsNullOrEmpty(requestedUri) ? String.Empty : requestedUri.ToLower();
            if (!requestedUri.StartsWith("/"))
            {
                requestedUri = String.Format("/{0}", requestedUri);
            }
            if (requestedUri.EndsWith("/"))
            {
                requestedUri = requestedUri.Substring(0, requestedUri.Length - 1);
            }

            if (requestedUri.EndsWith(".ashx"))
            {
                if (requestedUri == "/rss.ashx")
                {
                    requestCtx.RouteData.Values["controller"] = ContentCtrlr;
                    requestCtx.RouteData.Values["action"]     = "RSSFeed";
                    return(base.GetHttpHandler(requestCtx));
                }
                if (requestedUri == "/sitemap.ashx")
                {
                    requestCtx.RouteData.Values["controller"] = ContentCtrlr;
                    requestCtx.RouteData.Values["action"]     = "SiteMap";
                    return(base.GetHttpHandler(requestCtx));
                }

                //if (requestedUri == "/trackback.ashx") {	// will be dead link
                //	requestCtx.RouteData.Values["controller"] = ContentCtrlr;
                //	requestCtx.RouteData.Values["action"] = "Trackback";
                //	return base.GetHttpHandler(requestCtx);
                //}

                requestCtx.RouteData.Values["controller"] = ContentCtrlr;
                requestCtx.RouteData.Values["action"]     = "PageNotFound";
                requestCtx.RouteData.Values["id"]         = null;

                SiteData.WriteDebugException("cmsroutehandler ashx not matched", new Exception(String.Format("RequestedUri: {0}", requestedUri)));

                return(base.GetHttpHandler(requestCtx));
            }
            else if (requestedUri.EndsWith(".aspx"))
            {
                //since .aspx is not supported
                requestCtx.RouteData.Values["controller"] = ContentCtrlr;
                requestCtx.RouteData.Values["action"]     = "PageNotFound";
                requestCtx.RouteData.Values["id"]         = null;
            }
            else
            {
                string sCurrentPage = SiteData.CurrentScriptName;

                try {
                    string sScrubbedURL = SiteData.AlternateCurrentScriptName;

                    if (sScrubbedURL.ToLower() != sCurrentPage.ToLower())
                    {
                        requestedUri = sScrubbedURL;
                    }

                    SiteNav navData             = null;
                    bool    bIsHomePage         = false;
                    bool    bIgnorePublishState = SecurityData.AdvancedEditMode || SecurityData.IsAdmin || SecurityData.IsSiteEditor;

                    using (ISiteNavHelper navHelper = SiteNavFactory.GetSiteNavHelper()) {
                        if (SiteData.IsLikelyHomePage(requestedUri))
                        {
                            navData = navHelper.FindHome(SiteData.CurrentSiteID, !bIgnorePublishState);

                            if (navData != null)
                            {
                                requestedUri = navData.FileName;
                                bIsHomePage  = true;
                            }
                        }

                        if (!bIsHomePage)
                        {
                            navData = navHelper.GetLatestVersion(SiteData.CurrentSiteID, !bIgnorePublishState, requestedUri);
                        }

                        if ((SiteData.IsLikelyHomePage(requestedUri)) && navData == null)
                        {
                            navData = SiteNavHelper.GetEmptyHome();
                        }

                        requestCtx.RouteData.Values["controller"] = ContentCtrlr;
                        if (navData != null)
                        {
                            SiteData.WriteDebugException("cmsroutehandler != null", new Exception(String.Format("Default: {0}", navData.FileName)));
                            requestCtx.RouteData.Values["action"] = "Default";
                        }
                        else
                        {
                            SiteData.WriteDebugException("cmsroutehandler == null", new Exception(String.Format("_PageNotFound: {0}", sCurrentPage)));
                            requestCtx.RouteData.Values["action"] = "PageNotFound";
                        }
                        requestCtx.RouteData.Values["id"] = null;
                    }
                } catch (Exception ex) {
                    SiteData.WriteDebugException("cmsroutehandler_exception_uri", new Exception(String.Format("Exception: {0}", sCurrentPage)));

                    if (DatabaseUpdate.SystemNeedsChecking(ex) || DatabaseUpdate.AreCMSTablesIncomplete())
                    {
                        requestCtx.RouteData.Values["controller"] = ContentCtrlr;
                        requestCtx.RouteData.Values["action"]     = "Default";
                        requestCtx.RouteData.Values["id"]         = null;
                        SiteData.WriteDebugException("cmsroutehandler_exception_systemneedschecking", ex);
                    }
                    else
                    {
                        //something bad has gone down, toss back the error
                        SiteData.WriteDebugException("cmsroutehandler_exception", ex);
                        throw;
                    }
                }
            }

            return(base.GetHttpHandler(requestCtx));
        }
        public void ProcessRequest(HttpContext context)
        {
            using (ISiteNavHelper navHelper = SiteNavFactory.GetSiteNavHelper()) {
                SiteNav navData        = null;
                string  sFileRequested = context.Request.Path;
                sRequestedURL = sFileRequested;
                string sScrubbedURL = sFileRequested;

                sRequestedURL = SiteData.AppendDefaultPath(sRequestedURL);

                try {
                    sScrubbedURL = SiteData.AlternateCurrentScriptName;

                    if (sScrubbedURL.ToLower() != sRequestedURL.ToLower())
                    {
                        sFileRequested = sScrubbedURL;
                        bURLOverride   = true;
                    }

                    VirtualDirectory.RegisterRoutes();
                } catch (Exception ex) {
                    //assumption is database is probably empty / needs updating, so trigger the under construction view
                    if (DatabaseUpdate.SystemNeedsChecking(ex) || DatabaseUpdate.AreCMSTablesIncomplete())
                    {
                        if (navData == null)
                        {
                            navData = SiteNavHelper.GetEmptyHome();
                        }
                    }
                    else
                    {
                        //something bad has gone down, toss back the error
                        throw;
                    }
                }

                sFileRequested = SiteData.AppendDefaultPath(sFileRequested);

                if (context.User.Identity.IsAuthenticated)
                {
                    try {
                        if (context.Request.UrlReferrer != null && !string.IsNullOrEmpty(context.Request.UrlReferrer.AbsolutePath))
                        {
                            if (context.Request.UrlReferrer.AbsolutePath.ToLower().Contains(FormsAuthentication.LoginUrl.ToLower()) ||
                                FormsAuthentication.LoginUrl.ToLower() == sFileRequested.ToLower())
                            {
                                if (SiteFilename.DashboardURL.ToLower() != sFileRequested.ToLower() &&
                                    SiteFilename.SiteInfoURL.ToLower() != sFileRequested.ToLower())
                                {
                                    sFileRequested = SiteData.AdminDefaultFile;
                                }
                            }
                        }
                    } catch (Exception ex) { }
                }

                if (sFileRequested.ToLower().EndsWith(".aspx") || SiteData.IsLikelyHomePage(sFileRequested))
                {
                    bool bIgnorePublishState = SecurityData.AdvancedEditMode || SecurityData.IsAdmin || SecurityData.IsSiteEditor;

                    string queryString = String.Empty;
                    queryString = context.Request.QueryString.ToString();
                    if (string.IsNullOrEmpty(queryString))
                    {
                        queryString = String.Empty;
                    }

                    if (!CMSConfigHelper.CheckRequestedFileExistence(sFileRequested, SiteData.CurrentSiteID) || SiteData.IsLikelyHomePage(sFileRequested))
                    {
                        context.Items[REQ_PATH]  = context.Request.PathInfo;
                        context.Items[REQ_QUERY] = context.Request.QueryString.ToString();

                        // handle a case where this site was migrated from a format where all pages varied on a consistent querystring
                        // allow this QS parm to be set in a config file.
                        if (SiteData.IsLikelyHomePage(sFileRequested))
                        {
                            string sParm = String.Empty;
                            if (SiteData.OldSiteQuerystring != string.Empty)
                            {
                                if (context.Request.QueryString[SiteData.OldSiteQuerystring] != null)
                                {
                                    sParm = context.Request.QueryString[SiteData.OldSiteQuerystring].ToString();
                                }
                            }
                            if (!string.IsNullOrEmpty(sParm))
                            {
                                sFileRequested = "/" + sParm + ".aspx";

                                SiteData.Show301Message(sFileRequested);

                                context.Response.Redirect(sFileRequested);
                                context.Items[REQ_PATH]  = sFileRequested;
                                context.Items[REQ_QUERY] = String.Empty;
                            }
                        }

                        try {
                            //periodic test of database up-to-dated-ness
                            if (DatabaseUpdate.TablesIncomplete)
                            {
                                navData = SiteNavHelper.GetEmptyHome();
                            }
                            else
                            {
                                bool bIsHomePage = false;

                                if (SiteData.IsLikelyHomePage(sFileRequested))
                                {
                                    navData = navHelper.FindHome(SiteData.CurrentSiteID, !bIgnorePublishState);

                                    if (SiteData.IsLikelyHomePage(sFileRequested) && navData != null)
                                    {
                                        sFileRequested = navData.FileName;
                                        bIsHomePage    = true;
                                    }
                                }

                                if (!bIsHomePage)
                                {
                                    string pageName = sFileRequested;
                                    navData = navHelper.GetLatestVersion(SiteData.CurrentSiteID, !bIgnorePublishState, pageName);
                                }

                                if (SiteData.IsLikelyHomePage(sFileRequested) && navData == null)
                                {
                                    navData = SiteNavHelper.GetEmptyHome();
                                }
                            }
                        } catch (Exception ex) {
                            //assumption is database is probably empty / needs updating, so trigger the under construction view
                            if (DatabaseUpdate.SystemNeedsChecking(ex) || DatabaseUpdate.AreCMSTablesIncomplete())
                            {
                                if (navData == null)
                                {
                                    navData = SiteNavHelper.GetEmptyHome();
                                }
                            }
                            else
                            {
                                //something bad has gone down, toss back the error
                                throw;
                            }
                        }

                        if (navData != null)
                        {
                            string sSelectedTemplate = navData.TemplateFile;

                            // selectivly engage the cms helper only if in advance mode
                            if (SecurityData.AdvancedEditMode)
                            {
                                using (CMSConfigHelper cmsHelper = new CMSConfigHelper()) {
                                    if (cmsHelper.cmsAdminContent != null)
                                    {
                                        try { sSelectedTemplate = cmsHelper.cmsAdminContent.TemplateFile.ToLower(); } catch { }
                                    }
                                }
                            }

                            if (!CMSConfigHelper.CheckFileExistence(sSelectedTemplate))
                            {
                                sSelectedTemplate = SiteData.DefaultTemplateFilename;
                            }

                            sVirtualReqFile = sFileRequested;

                            if (bURLOverride)
                            {
                                sVirtualReqFile = sRequestedURL;
                                sFileRequested  = sRequestedURL;
                            }

                            RewriteCMSPath(context, sSelectedTemplate, queryString);
                        }
                        else
                        {
                            SiteData.PerformRedirectToErrorPage(404, sFileRequested);
                            SiteData.Show404MessageFull(true);
                        }
                    }
                    else
                    {
                        sVirtualReqFile = sFileRequested;

                        RewriteCMSPath(context, sVirtualReqFile, queryString);
                    }
                }

                context.ApplicationInstance.CompleteRequest();
            }
        }