acceptverbs

What is the default behaviour of a controller action not marked with AcceptVerbs, HttpGet or HttpPost?

◇◆丶佛笑我妖孽 提交于 2019-12-01 03:21:49
If I create a controller action and do not decorate it with AcceptVerbs , HttpPost or HttpGet . What is the default behaviour? Does the action allow any access method or does it default to GET ? It's accessible via any verb. In Web API 2.1: it depends on the name of the action. If the action starts with "Get*" then it will default to only accept GET requests. If it starts with "Put*" then it will default to only accept PUT requests. Same with POST. If it doesn't start with any known verb then it will default to only accept POST. Here are the results of my testing: public class BlahController :

Respond to HTTP HEAD requests using ASP.NET MVC

强颜欢笑 提交于 2019-11-29 05:24:51
I'd like to correctly support the HTTP HEAD request when bots hit my ASP.NET MVC site using HEAD. It was brought to my attention that all HTTP HEAD requests to the site were returning 404s, particularly from http://downforeveryoneorjustme.com . Which is really annoying. Wish they would switch to GET like all the other good bots out there. If I just change [AcceptVerbs(HttpVerbs.Get)] to [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Head)] will MVC know to drop the body of the request? What have you done to support HTTP HEAD requests? (Code sample would be great!) I created a simple action method in

ASP.NET MVC AcceptVerbs and registering routes

北城以北 提交于 2019-11-28 09:42:07
do I have to register the HttpVerb constraint in my route definition (when i'm registering routes) if i have decorated my action method with the [AcceptVerbs(..)] attribute already? eg. i have this. [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(FormCollection formCollection) { .. } do i need to add this to the route that refers to this action, as a constraint? Haacked The difference between the two is the following: Let's assume the Create method in question is on the HomeController . Using the AcceptVerbs attribute does not affect routing. It's actually something used by the action

Respond to HTTP HEAD requests using ASP.NET MVC

不羁的心 提交于 2019-11-27 22:56:42
问题 I'd like to correctly support the HTTP HEAD request when bots hit my ASP.NET MVC site using HEAD. It was brought to my attention that all HTTP HEAD requests to the site were returning 404s, particularly from http://downforeveryoneorjustme.com. Which is really annoying. Wish they would switch to GET like all the other good bots out there. If I just change [AcceptVerbs(HttpVerbs.Get)] to [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Head)] will MVC know to drop the body of the request? What have you

What is the default behaviour of a controller action not marked with AcceptVerbs, HttpGet or HttpPost?

人盡茶涼 提交于 2019-11-27 06:51:35
问题 If I create a controller action and do not decorate it with AcceptVerbs , HttpPost or HttpGet . What is the default behaviour? Does the action allow any access method or does it default to GET ? 回答1: It's accessible via any verb. 回答2: In Web API 2.1: it depends on the name of the action. If the action starts with "Get*" then it will default to only accept GET requests. If it starts with "Put*" then it will default to only accept PUT requests. Same with POST. If it doesn't start with any known

ASP.NET MVC AcceptVerbs and registering routes

我与影子孤独终老i 提交于 2019-11-27 03:06:56
问题 do I have to register the HttpVerb constraint in my route definition (when i'm registering routes) if i have decorated my action method with the [AcceptVerbs(..)] attribute already? eg. i have this. [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(FormCollection formCollection) { .. } do i need to add this to the route that refers to this action, as a constraint? 回答1: The difference between the two is the following: Let's assume the Create method in question is on the HomeController .