开发者

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 thi开发者_如何学Cs via ASP.NET MVC 3?


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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜