ASP.NET路由-末尾带有斜杠

| 考虑以下服务合同:
[WebGet(UriTemplate = \"/stores\")]
DTO.Stores GetAllStores();

[WebGet(UriTemplate = \"/stores/{name}\")]
DTO.Stores GetStores(string name);
我可以到达以下两个网址:http:// localhost / v1 / stores和http:// localhost / v1 / stores / Joe。但是,URL http:// localhost / v1 / stores /(注意末尾的斜杠)向我返回一个“找不到端点”错误。理想情况下,我希望http:// localhost / v1 / stores /调用GetAllStores()。 我怎样才能做到这一点?谢谢!
已邀请:
我会尝试插入波浪号。也许是“〜/ stores”? 或者,通过路由,将\“ / \”放在前面。
如果您使用\“ string?name \”作为参数怎么办?
[WebGet(UriTemplate = \"/stores/{name}\")]
DTO.Stores GetStores(string? name);
而且,由于两种方法都返回相同的内容(DTO.Stores),因此可以使用一种方法而不是两种方法来获取Stores(就像现在所做的那样)。像这样:
[WebGet(UriTemplate = \"/stores/{name}\")]
DTO.Stores GetStores(string? name)
{
    if(string.IsNullOrEmpty(name))
    {
        //get specific store
    }
    else
    {
        //get all stores
    }
}
附注:我不确定这是否可以与WCF一起使用,但请尝试一下。 ;-)

要回复问题请先登录注册