したがって、ActionFilter 属性の OnActionExecuting オーバーライドを使用して、アクションにこのセキュリティ設定を行いました。
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