csharp 一个过滤器(应该用作全局过滤器)来检查应用程序是否配置为脱机,并在此情况下抛出异常

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 一个过滤器(应该用作全局过滤器)来检查应用程序是否配置为脱机,并在此情况下抛出异常相关的知识,希望对你有一定的参考价值。

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.");
        }
    }
}

以上是关于csharp 一个过滤器(应该用作全局过滤器)来检查应用程序是否配置为脱机,并在此情况下抛出异常的主要内容,如果未能解决你的问题,请参考以下文章

vue过滤器

Vue.js过滤器

handsontable:全局搜索过滤器行为

Vue过滤器

csharp LINQ过滤器列表由另一个列表组成

将 django 用作独立模板引擎时如何使用自定义过滤器