Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调用操作方法时获取HTTP 404 not found错误_C#_Asp.net Web Api2_Asp.net Web Api Routing - Fatal编程技术网

C# 调用操作方法时获取HTTP 404 not found错误

C# 调用操作方法时获取HTTP 404 not found错误,c#,asp.net-web-api2,asp.net-web-api-routing,C#,Asp.net Web Api2,Asp.net Web Api Routing,请查看我申请的以下详细信息 public class CartController : ApiController { [HttpGet] public Response<CartDto> GetById(Guid customerId) { .... } } 网址 http://localhost:50300/api/Cart/GetById/customerId=5D5020DA-47DF-4C82-A722-C8DEAF06AE

请查看我申请的以下详细信息

public class CartController : ApiController
{
    [HttpGet]
    public Response<CartDto> GetById(Guid customerId)
    {
        ....
    }
}
网址

http://localhost:50300/api/Cart/GetById/customerId=5D5020DA-47DF-4C82-A722-C8DEAF06AE23

当我使用上面的URL调用action方法时,我得到了HTTP 404 Not Found。出了什么问题?

URL

 api/Cart/GetById/customerId=5D5020DA-47DF-4C82-A722-C8DEAF06AE23
操作参数名称
customerId
与路由模板不匹配

api/{controller}/{action}/{id}
更新操作

[HttpGet]
public Response<CartDto> GetById(Guid id) {
    //....
}

URL的主要问题是缺少
以指示查询字符串的开始:

http://localhost:50300/api/Cart/GetById/?customerId=5D5020DA-47DF-4C82-A722-C8DEAF06AE23

之后的所有内容都在查询字符串中,并按名称进行匹配(即
customerId
与您同名的参数进行匹配)。

如果您将
customerId=5D5020DA-47DF-4C82-A722-C8DEAF06AE23
更改为
,它是否有效?customerId=5D5020DA-47DF-4C82-A722-C8DEAF06AE23
是的,您是正确的。将url中customerId前面的斜杠改为问号后,效果很好。谢谢你的回答。
api/Cart/GetById/5D5020DA-47DF-4C82-A722-C8DEAF06AE23
http://localhost:50300/api/Cart/GetById/?customerId=5D5020DA-47DF-4C82-A722-C8DEAF06AE23