我想拒绝在周末访问某些网络方法。动作过滤器似乎是自然的载体。
public class RunMonThruFriAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
var today = DateTime.Now.DayOfWeek;
if (today == DayOfWeek.Saturday || today == DayOfWeek.Sunday)
throw new CustomException("Outside allowed or day time", 999);
}
}
这可行,但我真的不想抛出Exception
. 我可以使用什么来代替Exception
只是默默地拒绝进入?