当前 http 上下文的 HTTP 动词
如何找到用于访问应用程序的 http 动词(POST、GET、DELETE、PUT)?我正在寻找 httpcontext.current 但似乎没有是任何给我信息的财产。谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
使用HttpContext.Current.Request.HttpMethod。
请参阅:http://msdn.microsoft.com/en-us/library/ system.web.httprequest.httpmethod.aspx
Use
HttpContext.Current.Request.HttpMethod
.See: http://msdn.microsoft.com/en-us/library/system.web.httprequest.httpmethod.aspx
在 ASP.NET CORE 2.0 中,您可以使用以下命令获取(或设置)当前上下文的 HTTP 谓词:
In ASP.NET CORE 2.0 you can get (or set) the HTTP verb for the current context using:
用于获取 Get 和 Post
For getting Get and Post
您还可以使用:
HttpContext.Current.Request.RequestType
https://msdn.microsoft.com/en-us/library/system.web.httprequest.requesttype(v=vs.110).aspx
You can also use:
HttpContext.Current.Request.RequestType
https://msdn.microsoft.com/en-us/library/system.web.httprequest.requesttype(v=vs.110).aspx
在 ASP.NET Core v3.1 中,我使用注入到构造函数中的 HttpContextAccessor 接口检索当前的 HTTP 动词,例如
用法:
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.
Usage:
HttpContext.Current.Request.HttpMethod
返回字符串,但最好使用枚举 HttpVerbs。似乎没有内置方法来获取当前动词作为枚举,所以我为它编写了助手应用程序的助手类
基控制器类
HttpContext.Current.Request.HttpMethod
return string, but better use enum HttpVerbs. It seems there are no build in method to get currrent verb as enum, so I wrote helper for itHelper class
base controller class of application