我如何在同一个文件中访问两个WebAPI端点?(How can I access two WebAPI endpoints within the same file?)

编程入门 行业动态 更新时间:2024-10-26 00:24:24
我如何在同一个文件中访问两个WebAPI端点?(How can I access two WebAPI endpoints within the same file?)

目前我的设置包括两个位于同一C#文件中的WebAPI端点(POST和DELETE):

[HttpPost] [Route("api/authorizations/create/{id}")] public IHttpActionResult CreateAuthorization(string id); [HttpDelete] [Route("api/authorizations/delete/{id}")] public IHttpActionResult DeleteAuthorization(string id);

我可以使用Postman成功地将邮件发送到第一个终端,但是当我尝试向第二个终端发送DELETE请求时,我收到以下消息

404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

在本地测试这两个端点工作得很好,但是当我将我的项目上传到Staging环境时,我只能访问POST端点。

任何想法,为什么我只能访问一个? 同样,这两个端点位于同一个控制器文件中。

Currently the setup I have includes two WebAPI endpoints (POST and DELETE) that are located within the same C# file:

[HttpPost] [Route("api/authorizations/create/{id}")] public IHttpActionResult CreateAuthorization(string id); [HttpDelete] [Route("api/authorizations/delete/{id}")] public IHttpActionResult DeleteAuthorization(string id);

I can POST to the first endpoint successfully using Postman, but when I attempt to send a DELETE request to the second endpoint I get the following message

404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

Testing both of these endpoints locally worked just fine, but when I upload my project to a Staging environment I'm only able to access the POST endpoint.

Any idea why I can only access one? Again, these two endpoints are located within the same Controller file.

最满意答案

检查您的运行时托管环境。 如果它是像IIS(或任何其他)的东西, DELETE动词可能未启用。

Check your runtime hosting environment. If it's something like IIS (or any other), DELETE verb mightn't be enabled.

更多推荐

本文发布于:2023-07-20 20:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1203694.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   文件   在同一个   WebAPI   endpoints

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!