Disable action method from being called from the address bar

痴心易碎 提交于 2019-12-06 22:01:21

问题


I have a method in my controller that I don't want to be called from the address bar in the browser...

Is there a way to do that? Maybe some kind of annotation, modification in the route configuration? Which are my options?


回答1:


If you are going to use this action only from within your controller or Views then you can use ChildActionOnly attribute.

If you want to access it using POST then you can use [HttpPost] attribute.

But if you wish to use it using GET (i.e. using AJAX call etc) and don't want users to access it using address bar then you can follow this tutorial to make your actions AJAX only.

Or, if you simply want a method that is not an Action at all (i.e. cannot be called using HTTP) then you can either make it private or use [NonAction] attribute




回答2:


Use NonAction attribute on the method.



来源:https://stackoverflow.com/questions/16696976/disable-action-method-from-being-called-from-the-address-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!