因此,我使用 ActionFilter 属性的 OnActionExecuting 覆盖在我的 Action 上进行了此安全设置。
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
RouteValueDictionary routeDeniedUsers = new RouteValueDictionary(new { controller = "Errorhandler", action = "NopeAintAllowed"});
if(user.IsNotAllowed)
throw new System.Security.SecurityException("You are not allowed to access page")
return
try{
///some process
}catch(SecurityException ex){
if(ex != null)
filterContext.Result = new RedirectToRouteResult(routeDeniedUsers);
}
}
所以我的问题是,一旦用户到达那里,我如何向我的“routeDeniedusers”操作显示错误消息?我会使用 TempData["key"] 但 Visual Studio 只在工具提示上显示 TempDataDictionary (或者任何你称之为显示语法的东西)。我想访问 SecurityException 实例,但我不知道如何。
我真的应该在传递中使用 SecurityException 对象还是应该使用其他东西?任何建议表示赞赏。
谢谢,G