且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

没有HTTP资源被发现在的ASP.NET Web API请求URI匹配错误

更新时间:2021-11-23 21:38:48

OK,然后...感谢把单元测试想法我的头,它加快东西极大。

OK then... thanks for putting the unit test idea in my head, it sped things up immensely.

这里的内幕:

您可以有不同的动词相同的参数签名(获得放后删除)。

You can have identical parameter signatures on different verbs (get post put delete).

您的不能有不同的操作名称相同的参数签名在同一个动词。

You cannot have identical parameter signatures on different action names on the same verb.

您只需要有所不同的有一个参数名称。

You only need vary one parameter name.

因此​​,这是确定的,因为他们都在不同的动词

So this is ok because they're all on different verbs

[HttpDelete, ActionName("Delete")]
public void Delete(Guid sessionId, Guid fileId) {...}

[HttpGet, ActionName("Cancel")]
public bool Cancel(Guid sessionId, Guid fileId) {...}

[HttpPost, ActionName("FileChunk")] 
public void PostFileChunk(Guid sessionId, Guid fileId) {...}

但由于他们都得到这个不冷静

but this is not cool because they're both gets

[HttpGet, ActionName("UploadedBytes")]
public long GetUploadedByteCount(Guid sessionId, Guid fileId) {...}

[HttpGet, ActionName("Cancel")]
public bool Cancel(Guid sessionId, Guid fileId) {...}

和您可以修复它​​像这样

and you can fix it like this

[HttpGet, ActionName("UploadedBytes")]
public long GetUploadedByteCount(Guid sessionId, Guid uploadBytesFileId) {...}

[HttpGet, ActionName("Cancel")]
public bool Cancel(Guid sessionId, Guid cancelFileId) {...}

也许我是一个硬的屁股,但据我而言它不是路由,直到方法被调用。

Maybe I'm a hard-ass but as far as I'm concerned it isn't routing until the method is called.