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
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
if (HttpContext.Request.HttpMethod == HttpMethod.Post.Method)
{
// The action is a post
}
if (HttpContext.Request.HttpMethod == HttpMethod.put.Method)
{
// The action is a put
}
if (HttpContext.Request.HttpMethod == HttpMethod.DELETE.Method)
{
// The action is a DELETE
}
if (HttpContext.Request.HttpMethod == HttpMethod.Get.Method)
{
// The action is a Get
}
In ASP.NET Core v3.1 I retrieve the current HTTP verb by using the HttpContextAccessor interface which is injected in on the constructor, e.g.
private readonly IHttpContextAccessor _httpContextAccessor;
public MyPage(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
Usage:
_httpContextAccessor.HttpContext.Request.Method