In the standard MVC project using ASP.NET Identity, an unauthorized request is redirected to the login page, and a ReturnUrl
parameter is added to the query string so that after a successful login a further redirect can be made to the originally-requested page.
The Account controller contains a method named RedirectToLocal
that's used to perform that second redirect only if the ReturnUrl
parameter refers to a local URL (i.e. a page from the same website). It uses a very simplistic approach to perform this check, and does not check (for example) that the URL is a valid URL, or that it can be routed to an action.
In my case, there are some URLs that I definitely don't want to redirect to, such as the log-out page(!). I'd also like to redirect only to URLs that can be successfully routed.
To achieve that, I've changed the code to turn the URL into a route (using a technique similar to this). That gets me a RouteData
object that allows me to examine the controller and action names (and thus lets me exclude certain blocked actions).
I'd like to take this further and exclude any controller actions that expect POST data (since you cannot redirect to those). So...
Given a controller name and action name, how can I tell whether this is a GET or a POST action?
Is there some way I can invoke the routing/binding that the MVC framework would normally do, right up to the point before it actually executes the action?