user1534664
user1534664

Reputation: 3418

make action method only accessible through redirect

I'm trying to submit a form. When the form is submitted I want the form to dissapear and the text Thanks for your support. An e-mail will be sent to you as soon as possible. to show.

I think the most logical way to go by this is by making the form submit to the action SaveMessage() that redirects to the action RedirectToAction("MessageSaved") that returns the view with the message. If it isn't, please say so. This is for practice.

The problem is that the message can be viewed as well by going to /Support/MessageSaved. How do I prevent users from accessing it by url, but make the action accessible by redirectToAction()?

Upvotes: 3

Views: 810

Answers (1)

GalacticCowboy
GalacticCowboy

Reputation: 11759

Set a value in TempData before the redirect. In the MessageSaved action method, check for that value before showing the form. Otherwise, redirect to another page.

Upvotes: 4

Related Questions