using System;
namespace Utility
{
public class OfflineException : ApplicationException
{
public OACSOfflineException(string message)
: base(message)
{
}
}
}
// Apply a filter so that Elmah does not log any "system offline" exceptions. Otherwise the log will
// be flooded with those messages as users try to access the system while it is down for maintenance.
void ErrorLog_Filtering(object sender, Elmah.ExceptionFilterEventArgs e)
{
if (e.Exception is OfflineException)
e.Dismiss();
}
using System;
using System.Net;
using System.Web.Mvc;
using System.Web.Routing;
namespace Web.Filters
{
/// <summary>
/// Check whether the application is marked as offline in the config file.
/// If so, and the user does not have the override permission, throw an exception.
/// The MVC error handling will deal with displaying the exception message to the user.
/// </summary>
public class CheckApplicationOfflineAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// Only need to carry out the check on parent actions, otherwise there is an unnecessary overhead
if (filterContext.IsChildAction)
return;
if (ConfigurationHelper.ApplicationOffline && !SecurityHelper.UserHasApplicationOfflineOverridePermission)
throw new OfflineException("The system is offline for maintenance.");
}
}
}