【问题标题】:How to approach debugging 404 on a route?如何在路由上调试 404?
【发布时间】:2017-01-27 05:35:42
【问题描述】:

为了获得 404,我做错了什么?

我正在向我的控制器发出请求:

/// <category>Public Note operations</category>
/// <summary>   Gets the public note for the specified entity. </summary> 
/// <returns>   Note matching unique NoteId identifier. </returns>
/// <example>
///     Sample URI handled by this method is:
///     <code>
///       http://localhost:5001/ooo360/api/v2/Note(4a872b89-f42e-e511-9419-00155d104c97)/attachment
///     </code>
/// </example>
[Route("{entityLogicalName}/({entityGuid:guid})/PublicNotes", Name = "GetPublicNotesForEntity")]         
[HttpGet]
public IEnumerable<Annotation> GetPublicNotesForEntity(string entityLogicalName, Guid entityGuid)
{
    // there's a breakpoint here that never even gets triggered
    return this._PublicNoteService.Get(entityLogicalName, entityGuid);
}

一个请求的例子是:

http://localhost:5001/ooo360/api/v2/TroubleTicket(058A9570-D373-E511-9420-00155D10416C)/PublicNotes

我做错了什么?

【问题讨论】:

  • ~ 你是否在 web api 配置中启用了属性路由? ~在TroubleTicket 和Guid - localhost:5001/ooo360/api/v2/TroubleTicket/… 之间不应该有一个/ ~ 你是否设置了正确的路由前缀以便ooo360/api/v2 得到解决?
  • 非常感谢你发现这个愚蠢的错误,缺少斜线

标签: c# asp.net-web-api routes


【解决方案1】:

需要验证的几件事:

~ 你是否在 web api 配置中启用了属性路由?

~在TroubleTicket 和 Guid 之间不应该有/ - http://localhost:5001/ooo360/api/v2/TroubleTicket/(058A9570-D373-E511-9420-00155D10416C)/PublicNotes

~ 你是否设置了正确的路由前缀以便ooo360/api/v2 得到解析?

【讨论】:

    猜你喜欢
    • 2012-12-19
    • 2020-03-18
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    • 2021-07-27
    • 1970-01-01
    相关资源
    最近更新 更多