たいのですがリダイレクトの後ActionResultて決められますか?
-
20-08-2019 - |
質問
にASP.NET MVCをしたいと思っていう:
- のだが、ベースコントローラーをチェックの種類
ActionResult
. - の場合
ActionResult
はViewResult
, 負荷の一部を共有データのためのすべてます。 - 場合、共有データを満たす特定の基準は、リダイレクトにログインページです。
かを実行します。
ことも考えていましたが、以下のものようにリダイレクトな作行為によって、既に実行されているか?).があるので、周辺か。
public abstract class BaseController : Controller
{
protected override void OnActionExecuted
(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
// If the result is a view result,
// then it loads the shared data (for use in shared view):
if (filterContext.Result is ViewResult)
LoadSharedData();
}
private void LoadSharedData()
{
// TODO: Loads the data that is common for all views.
// TODO: If the shared data fulfills some specific criteria,
// it will redirect to a login page.
Redirect("http://someurl");
}
}
解決
私はこれを試みることによって答えを見つけたと思う。
filterContext.Result = Redirect("http://someurl");
これは動作します。
所属していません StackOverflow