Skip to content

Commit b4df764

Browse files
committed
Check everything - even things that really can't be null.
1 parent 0dcf5c2 commit b4df764

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

Our.Umbraco.MaintenanceMode/Controllers/MaintenanceModeMvcController.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text;
66
using System.Threading.Tasks;
77
using System.Web.Mvc;
8+
using Umbraco.Core.Logging;
89
using Umbraco.Core.Security;
910
using Umbraco.Web.Models;
1011
using Umbraco.Web.Mvc;
@@ -15,34 +16,39 @@ public class MaintenanceModeMvcController
1516
: RenderMvcController
1617
{
1718
public override ActionResult Index(RenderModel model)
18-
{
19-
if (MaintenanceMode.Current.Status.IsInMaintenanceMode
20-
&& ApplicationContext.IsConfigured)
19+
{
20+
try
2121
{
22-
if (MaintenanceMode.Current.Status.Settings.AllowBackOfficeUsersThrough
23-
&& IsBackOfficeUserLoggedIn())
22+
if (ApplicationContext != null
23+
&& ApplicationContext.IsConfigured
24+
&& MaintenanceMode.Current.Status.IsInMaintenanceMode)
2425
{
25-
return base.Index(model);
26-
}
26+
if (MaintenanceMode.Current.Status.Settings.AllowBackOfficeUsersThrough
27+
&& IsBackOfficeUserLoggedIn())
28+
{
29+
return base.Index(model);
30+
}
31+
32+
if (Response != null)
33+
Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
2734

28-
Response.StatusCode = (int)HttpStatusCode.ServiceUnavailable;
29-
return View(MaintenanceMode.Current.Status.Settings.TemplateName, model);
35+
return View(MaintenanceMode.Current.Status.Settings.TemplateName, model);
36+
}
37+
}
38+
catch(Exception ex)
39+
{
40+
Logger.Warn<MaintenanceModeMvcController>("Checking Maintance Mode Failed: {0}", () => ex.Message);
3041
}
3142

3243
return base.Index(model);
33-
3444
}
3545

3646
private bool IsBackOfficeUserLoggedIn()
3747
{
38-
var userTicket = this.HttpContext.GetUmbracoAuthTicket();
39-
if (userTicket != null)
40-
{
48+
if (HttpContext != null && HttpContext.GetUmbracoAuthTicket() != null)
4149
return true;
42-
}
43-
50+
4451
return false;
45-
4652
}
4753
}
4854
}

Our.Umbraco.MaintenanceMode/MaintenanceMode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private MaintenanceModeStatus InitializeStatus()
6464
{
6565
MaintenanceModeStatus status = null;
6666

67-
if (File.Exists(configFilePath))
67+
if (configFilePath != null && File.Exists(configFilePath))
6868
{
6969
try
7070
{

0 commit comments

Comments
 (0)