1
- namespace BlogEngine . Core . Web . Controls
1
+ using System . IO ;
2
+
3
+ namespace BlogEngine . Core . Web . Controls
2
4
{
3
5
using System ;
4
6
using System . Web ;
@@ -256,34 +258,39 @@ protected override void Render(HtmlTextWriter writer)
256
258
/// <returns>Path to the master page</returns>
257
259
string GetSiteMaster ( )
258
260
{
259
- if ( Request . FilePath . Contains ( "post.aspx" , StringComparison . InvariantCultureIgnoreCase ) )
261
+ if ( FilePathContains ( "post.aspx" ) )
260
262
{
261
263
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 ) ) )
263
265
return path ;
264
266
}
265
267
266
268
// if page.master exists, use it for all common pages
267
269
// 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 )
274
271
{
275
272
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 ) ) )
277
274
return path ;
278
275
}
279
276
280
277
var siteMaster = $ "{ Utils . ApplicationRelativeWebRoot } Custom/Themes/{ BlogSettings . Instance . GetThemeWithAdjustments ( null ) } /site.master";
281
278
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" ) ;
286
290
291
+ private bool FilePathContains ( string path )
292
+ {
293
+ return Request . FilePath . Contains ( path , StringComparison . InvariantCultureIgnoreCase ) ;
287
294
}
288
295
}
289
296
}
0 commit comments