1- namespace BlogEngine . Core . Web . Controls
1+ using System . IO ;
2+
3+ namespace BlogEngine . Core . Web . Controls
24{
35 using System ;
46 using System . Web ;
@@ -256,34 +258,39 @@ protected override void Render(HtmlTextWriter writer)
256258 /// <returns>Path to the master page</returns>
257259 string GetSiteMaster ( )
258260 {
259- if ( Request . FilePath . Contains ( "post.aspx" , StringComparison . InvariantCultureIgnoreCase ) )
261+ if ( FilePathContains ( "post.aspx" ) )
260262 {
261263 string path = $ "{ Utils . ApplicationRelativeWebRoot } Custom/Themes/{ BlogSettings . Instance . Theme } /post.master";
262- if ( System . IO . File . Exists ( Server . MapPath ( path ) ) )
264+ if ( File . Exists ( Server . MapPath ( path ) ) )
263265 return path ;
264266 }
265267
266268 // if page.master exists, use it for all common pages
267269 // and site.master only for post list
268- if ( Request . FilePath . Contains ( "page.aspx" , StringComparison . InvariantCultureIgnoreCase ) ||
269- Request . FilePath . Contains ( "archive.aspx" , StringComparison . InvariantCultureIgnoreCase ) ||
270- Request . FilePath . Contains ( "contact.aspx" , StringComparison . InvariantCultureIgnoreCase ) ||
271- Request . FilePath . Contains ( "error.aspx" , StringComparison . InvariantCultureIgnoreCase ) ||
272- Request . FilePath . Contains ( "error404.aspx" , StringComparison . InvariantCultureIgnoreCase ) ||
273- Request . FilePath . Contains ( "search.aspx" , StringComparison . InvariantCultureIgnoreCase ) )
270+ if ( PageMasterExists )
274271 {
275272 string path = $ "{ Utils . ApplicationRelativeWebRoot } Custom/Themes/{ BlogSettings . Instance . Theme } /page.master";
276- if ( System . IO . File . Exists ( Server . MapPath ( path ) ) )
273+ if ( File . Exists ( Server . MapPath ( path ) ) )
277274 return path ;
278275 }
279276
280277 var siteMaster = $ "{ Utils . ApplicationRelativeWebRoot } Custom/Themes/{ BlogSettings . Instance . GetThemeWithAdjustments ( null ) } /site.master";
281278
282- if ( System . IO . File . Exists ( Server . MapPath ( siteMaster ) ) )
283- return siteMaster ;
284- else
285- return $ "{ Utils . ApplicationRelativeWebRoot } Custom/Themes/Standard/site.master";
279+ return File . Exists ( Server . MapPath ( siteMaster ) )
280+ ? siteMaster
281+ : $ "{ Utils . ApplicationRelativeWebRoot } Custom/Themes/Standard/site.master";
282+ }
283+
284+ private bool PageMasterExists => FilePathContains ( "page.aspx" ) ||
285+ FilePathContains ( "archive.aspx" ) ||
286+ FilePathContains ( "contact.aspx" ) ||
287+ FilePathContains ( "error.aspx" ) ||
288+ FilePathContains ( "error404.aspx" ) ||
289+ FilePathContains ( "search.aspx" ) ;
286290
291+ private bool FilePathContains ( string path )
292+ {
293+ return Request . FilePath . Contains ( path , StringComparison . InvariantCultureIgnoreCase ) ;
287294 }
288295 }
289296}
0 commit comments