Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http verb of current http context

Tags:

c#

http

asp.net

How do you find the http verb (POST,GET,DELETE,PUT) used to access your application? Im looking httpcontext.current but there dosent seem to be any property that gives me the info. Thanks

like image 291
Tom Squires Avatar asked Aug 01 '11 12:08

Tom Squires


People also ask

What is HTTP current context?

The HttpContext encapsulates all the HTTP-specific information about a single HTTP request. When an HTTP request arrives at the server, the server processes the request and builds an HttpContext object. This object represents the request which your application code can use to create the response.

How do I access HTTP context?

ASP.NET Core apps access HttpContext through the IHttpContextAccessor interface and its default implementation HttpContextAccessor. It's only necessary to use IHttpContextAccessor when you need access to the HttpContext inside a service.

Which class represent the current HTTP request context?

Access current information using HttpContext class The first line shows the current URL of the HTTP request, the second line shows the number of session variables associated with the current request.

Why HttpContext current is null?

It won't work in the scheduling related class because relevant code is not executed on a valid thread, but a background thread, which has no HTTP context associated with. Overall, don't use Application["Setting"] to store global stuffs, as they are not global as you discovered.


2 Answers

Use HttpContext.Current.Request.HttpMethod.

See: http://msdn.microsoft.com/en-us/library/system.web.httprequest.httpmethod.aspx

like image 167
Daniel A. White Avatar answered Oct 02 '22 08:10

Daniel A. White


HttpContext.Current.Request.HttpMethod 
like image 37
spender Avatar answered Oct 02 '22 08:10

spender