我使用流行的Elmah.MVC error logging NuGet包。这样我就可以导航到/elmah来查看我的错误日志。我有以下IgnoreRoute语句,以便MVC忽略/elmah路由:
routes.IgnoreRoute("elmah");
routes.IgnoreRoute("elmah/{*pathinfo}");我已经编写了以下授权过滤器。当我导航到/elmah时,如何停止执行下面的过滤器。当然,它肯定有某种方法来尊重我告诉它忽略的路由?
public class MyFilterAttribute : FilterAttribute, IAuthorizationFilter
{
public void OnAuthorization(AuthorizationContext filterContext)
{
// I don't want /elmah routes to execute this.
}
}发布于 2015-05-21 17:06:36
解决方案是检查正在执行的ControllerName,如果是Elmah,则返回并忽略此请求。
public class MyFilterAttribute : FilterAttribute, IAuthorizationFilter
{
public void OnAuthorization(AuthorizationContext filterContext)
{
// I don't want /elmah routes to execute for this filter.
string controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
if (string.Equals(controllerName, "Elmah", StringComparison.Ordinal))
{
return;
}
}
}https://stackoverflow.com/questions/29942318
复制相似问题