Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If I do not specify [httpGet] or [httpPost] for the action method , what will be the rule for calling it

Previously as many articles mentioned that HttpGet is the default http method. For example if I have the following action method inside asp.net mvc web application, without any [httpGet] or [HttpPost]:-

Public ActionResult TestMethod(int I =0)

So I thought that this action method will be defined as Get action method, and will NOT be reachable if I send Posr request as follow “POST http://severname/test/TestMethod?i=1”.

But seems that my action method will be available for both Post & Get requests, when I do not specify any http method. So as I know that HttpGet is the default , but seems this is not the case? Or I am missing something about what does httpGet is the default mean? Can anyone advice please? Thanks

like image 751
john Gu Avatar asked Oct 23 '14 16:10

john Gu


People also ask

Can we use HttpPost instead of HttpGet?

HTTPPost method hides information from URL and does not bind data to URL. It is more secure than HttpGet method but it is slower than HttpGet. It is only useful when you are passing sensitive information to the server.

What is HttpPost and HttpGet?

HttpGet and HttpPost both are the attributes used in asp.net mvc application. We use both attributes on action represents the http requests like whether it is get request or post request.

Which is the default HTTP method for an action method HttpPost HttpGet HttpPut HttpDelete?

The MVC framework includes HttpGet, HttpPost, HttpPut, HttpDelete, HttpOptions, and HttpPatch action verbs. You can apply one or more action verbs to an action method to handle different HTTP requests. If you don't apply any action verbs to an action method, then it will handle HttpGet request by default.

What is HttpGet used for?

HTTP GET: The Hypertext Transfer Protocol(HTTP) Get method is mainly used at the client (Browser) side to send a request to a specified server to get certain data or resources.


1 Answers

What I understand, By default It accept both type of request whether it is GET or POST. but when a action method is decorated with either [httpGet] or [httpPost] attribute then the action method accepts only those request method which define by attribute.

like image 89
Mohd. Shaukat Ali Avatar answered Sep 20 '22 16:09

Mohd. Shaukat Ali