Reputation: 327
In my MVC application, I dont want any user to type in the address bar of the browser and navigate to any controller action directly.Can I enable this for the whole application?if yes ,How? Can you please let me know the concept name ?
Also I dont want to do that through Request.URLReferrer
because it has its own security risks (per Avoiding user to navigate to a view by entering url in the browser)
Thanks in advance!
Upvotes: 1
Views: 2274
Reputation: 62498
You need to use Custom Action Filter Attributes, See :
http://www.asp.net/mvc/tutorials/hands-on-labs/aspnet-mvc-4-custom-action-filters
****Updated:**
As Parsanna mentioned in comment,
You can use the [ChildActionOnly]
attribute on your action method to make sure it's not called directly, or use the ControllerContext.IsChildAction
property inside your action to determine if you want to redirect.
See :Asp.net mvc How to prevent browser from calling an action method?
Upvotes: 1