示例#1
0
        public string GetMasterPageFilePath()
        {
            string masterFilePath = HttpContext.Current.Request["masterFilePath"];

            if (masterFilePath == null)
            {
                masterFilePath = "";
            }

            var useMobile = ((!GetType().BaseType.Namespace.Contains(".Admin") && (IsMobile)));

            if (GetType().BaseType.Namespace.Contains(".Admin"))
            {
                if (File.Exists(URIHelper.ConvertToAbsPath(masterFilePath)))
                {
                    return(masterFilePath);
                }

                return(Page.MasterPageFile);
            }

            if (string.IsNullOrEmpty(masterFilePath) && FrameworkSettings.Current?.CurrentMediaDetail != null)
            {
                var masterPage = ((MediaDetail)FrameworkSettings.Current.CurrentMediaDetail).GetMasterPage();

                if (masterPage != null)
                {
                    masterFilePath = masterPage.PathToFile;

                    if (useMobile)
                    {
                        masterFilePath = masterPage.GetMobileTemplate();
                    }

                    if (masterPage.UseLayout)
                    {
                        masterFilePath = "";
                    }
                }
                else
                {
                    if ((FrameworkSettings.Current.CurrentMediaDetail.Handler == null) || (FrameworkSettings.Current.CurrentMediaDetail.Handler == ""))
                    {
                        var mediaType = FrameworkSettings.Current.CurrentMediaDetail.MediaType;

                        if (mediaType.MasterPage == null)
                        {
                            var defaultMaster = MasterPagesMapper.GetDefaultMasterPage();

                            if (defaultMaster != null)
                            {
                                masterFilePath = defaultMaster.PathToFile;

                                if (useMobile)
                                {
                                    masterFilePath = defaultMaster.GetMobileTemplate();
                                }
                            }
                        }
                        else
                        {
                            masterFilePath = mediaType.MasterPage.PathToFile;

                            if (useMobile)
                            {
                                masterFilePath = mediaType.MasterPage.GetMobileTemplate();
                            }
                        }
                    }
                    else
                    {
                        masterPage = MasterPagesMapper.GetByPathToFile(Page.MasterPageFile);

                        if (useMobile)
                        {
                            masterFilePath = masterPage?.MobileTemplate;
                        }
                        else
                        {
                            masterFilePath = masterPage?.PathToFile;
                        }
                    }
                }
            }

            return(masterFilePath);
        }