gpt4 book ai didi

asp.net-mvc - 从 ActionFilter 重定向到 Action

转载 作者:行者123 更新时间:2023-12-02 00:38:22 26 4
gpt4 key购买 nike

如何从自定义 ActionFilter 访问 RedirectToAction?

public class ExceptionHandlingFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (filterContext.Exception != null && !filterContext.ExceptionHandled)
{
filterContext.ExceptionHandled = true;

// HERE : RedirectToAction("ServiceNotFound","Error");

}
base.OnActionExecuted(filterContext);
}
}

最佳答案

试试这个:

filterContext.Result = new RedirectToRouteResult(
new System.Web.Routing.RouteValueDictionary {
{"controller", "Error"}, {"action", "ServiceNotFound"}
}
);

关于asp.net-mvc - 从 ActionFilter 重定向到 Action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1192692/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com