Implementing ExceptionFilterAttribute OnException method and need to redirect The old implementation (.Net 48) was
exceptionContext.Controller.TempData.Remove("");
exceptionContext.Controller.TempData.Add("");//exception message is added
exceptionContext.Controller.ControllerContext.HttpContext.Response.Redirect(url);
For the redirect I guess I can:
exceptionContext.HttpContext.Response.Redirect(url);//Is this correct?
Please suggest alternate for the remove and add?
In .net 6,there's no
exceptionContext.Controller.TempDataif you want to access TempData in your ExceptionFilter,you could try to inject the TempdataDictionaryFactory into the filterFor example, I tried as below:
in Program.cs:
The Result: