I have a custom action filter that inside OnActionExecuting , depending on certain criteria, displays the user and redirects him to the websiteโs home page. Code (taken back) for the redirect part below
filterContext.Controller.TempData.Add("key", "Message"); filterContext.Result = new RedirectResult("/");
As above, I also set the tempData message. Since the user is logged out, when they get to the main page, the [Authorize] attribute will redirect them to the GET login page. In the login view, I show any messages from tempData. However, in this situation tempData is empty.
This is very similar to how my POST login works (if it is not valid, it is redirected to the house, which redirects the login and displays the tempData message that was set in the "Login" message). This code can be seen below.
TempData.Add("key", errorMessage); return Redirect("/"));
The reason I do it this way, and not specifically redirect to the login page, is because this code is distributed to many sites, so we donโt know what the login URL is.
Does anyone have any info on why this works for POST login but not for ActionFilter Redirection?
Edit:
If I remove the exit call from the custom action filter, tempData is still set in the Home action, but that doesn't explain why it works for POST login, but not for the action filter?
Rob
source share