Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()?

like image 787
user1534664 Avatar asked Dec 29 '25 10:12

user1534664


1 Answers

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.

like image 154
GalacticCowboy Avatar answered Dec 31 '25 00:12

GalacticCowboy