user123093
user123093

Reputation: 2507

ASP MVC: ActionFilter attribute -> RedirectToRouteResult always redirect to HTTP GET

I have an ActionFilter attribute at the top of my controller.

[HandleError]
[MyActionFilter]
public class AccountController : Controller
{
  ...
}

When an action is received, i want to add/change some route values and then redirect to a correct route.

filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new { lang = langName, controller = controllerName, action = actionName, id = idName }));

This is working fine. However, the redirection is always set to HTTP GET, and since some of my actions are set to receive only HTTP POST, it fails.

Is there any way to make the redirection be HTTP POST?

Upvotes: 2

Views: 2039

Answers (2)

Saeed Neamati
Saeed Neamati

Reputation: 35822

As you said, you are redirecting your users to another action. This in HTTP protocol means that you send codes 301, 302, or 303 alongside your response to clients' browser.

Browser on the other hand always sends an HTTP Get in reaction to an HTTP redirection.

Thus, your answer is:

No

Upvotes: 0

Darin Dimitrov
Darin Dimitrov

Reputation: 1038800

Is there any way to make the redirection be HTTP POST?

No. The verb GET is at the very base of the definition of a redirect in the HTTP specification. It simply doesn't make sense to talk about an HTTP redirect and an HTTP verb different than GET.

Instead of redirecting you could return a view directly:

var result = new ViewResult
{
    ViewName = "~/Views/Shared/SomeView.cshtml",
};
result.Model = new MyViewModel();
filterContext.Result = result;

Upvotes: 6

Related Questions