开发者

asp.net mvc - [HttpPost/HttpGet] vs. [AcceptVerbs(HttpVerbs.Post/Get)]

开发者 https://www.devze.com 2023-02-05 11:17 出处:网络
are these things the same? [HttpPost/HttpGet] vs. [AcceptVerbs(HttpVerbs.Post开发者_开发知识库/Get)]

are these things the same?

[HttpPost/HttpGet] vs. [AcceptVerbs(HttpVerbs.Post开发者_开发知识库/Get)]

if not where is a difference?


Yes, absolutely the same. [HttpPost/HttpGet] were introduced in ASP.NET MVC 2 to reduce the keystrokes we have to type :-) [AcceptVerbs(HttpVerbs.Post/Get)] could still be used and behave the same although if you are writing new code I would recommend the first.


Yes they are the same but with the newer versions you can only make an action accept requests from one verb. Using [AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get | HttpVerbs.Delete)] you can accept 2 or more. Also you can use [AcceptVerbs] to accept other verbs that are not part of the HttpVerbs enum - eg. [AcceptVerbs("Trace")].

I'm not sure why you would ever need to use this functionality but you are able to should you wish.

0

精彩评论

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