How do I prevent a user from manually typing in the URL of a page in MVC?
For instance, I have a controller method which returns an error view:
// GET: /Checkout/Error
public ActionResult Error()
{
return View("Error")
}
EDIT: and a controller method that returns a success view:
// GET: /Checkout/Complete
public ActionResult Complete()
{
var order = /* get the order */
return View("Complete", order)
}
I redirect to it if something goes wrong in the order process:
public ActionResult Submit()
{
if (/*order succeeds*/) {
return RedirectToAction("Complete");
}
else
return RedirectToAction("Error");
}
But a user can manually type in "www.mysite.com/Checkout/Error" and get the error view outside of the context of the checkout workflow.
I did some looking around and found ChildActionOnly, but that only seems to apply to calling actions from within views, which doesn't apply here.
I suppose I could manually check at the beginning of the Error action method to see if indeed there was a problem with the order, and return the error view in that case and redirect the user otherwise, but it seems like there has to be a simpler way to prevent users from manually navigating to pages like this.
EDIT: The same applies to the completed view. A user can type in the URL which corresponds to the action. How do I prevent this action from being invoked like this?