Chuck Norris
Chuck Norris

Reputation: 15190

How to block access to controller via changing Url in ASP.NET MVC?

I want to access page with Success message only, when user clicks to button...

By changing url, such as .../Success I want my site redirect user to previous page.

How can I do this via ASP.NET MVC 3?

Upvotes: 2

Views: 2536

Answers (2)

Amir
Amir

Reputation: 9627

A quick way of doing that is to set a session containing a random number in the action which is redirecting, also pass the random number as a parameter to the other action.

Inside the other action(redirected one), compare the value of the session with the parameter of the action. If values are equal, the user is getting there by pressing button, otherwise, the user gets there by changing the URL. Hope it helps.

Upvotes: 3

Rashmi Pandit
Rashmi Pandit

Reputation: 23788

You can redirect to the specific action using:

RedirectToAction(string actionName);

If the action belongs to another controller, you can use this overload:

RedirectToAction(string actionName, string controllerName);

Upvotes: 1

Related Questions