这条路线有什么问题
What's wrong with this route
鉴于以下情况:
namespace Foo.Controllers
{
[RoutePrefix("api/route")]
public class SnoconesFooBarController : BaseApiController
{
/// <summary>
/// Asks for a new foo to be created to the given subnet with the specific bar named
/// </summary>
/// <param name="fooName"></param>
/// <param name="uriString"></param>
/// <returns></returns>
[Route("newFoo/{fooName}")]
public async Task<IHttpActionResult> PostNewFooForSpecificBar(string fooName, string uriString)
{
}
}
为什么当我尝试 post 时收到 404:
http://localhost:4471/api/route/newFoo/test1
具有以下负载:
FWIW,我通过将其更改为如下所示来修复它:
namespace Foo.Controllers
{
[RoutePrefix("api/route")]
public class SnoconesFooBarController : BaseApiController
{
/// <summary>
/// Asks for a new foo to be created to the given subnet with the specific bar named
/// </summary>
/// <param name="fooData"></param>
/// <returns></returns>
[Route("newFoo/")]
public async Task<IHttpActionResult> PostNewFooForSpecificBar(FooRequestObject fooData)
{
}
}
并在 FooRequestObject 中包含我需要的所有数据
鉴于以下情况:
namespace Foo.Controllers
{
[RoutePrefix("api/route")]
public class SnoconesFooBarController : BaseApiController
{
/// <summary>
/// Asks for a new foo to be created to the given subnet with the specific bar named
/// </summary>
/// <param name="fooName"></param>
/// <param name="uriString"></param>
/// <returns></returns>
[Route("newFoo/{fooName}")]
public async Task<IHttpActionResult> PostNewFooForSpecificBar(string fooName, string uriString)
{
}
}
为什么当我尝试 post 时收到 404:
http://localhost:4471/api/route/newFoo/test1
具有以下负载:
FWIW,我通过将其更改为如下所示来修复它:
namespace Foo.Controllers
{
[RoutePrefix("api/route")]
public class SnoconesFooBarController : BaseApiController
{
/// <summary>
/// Asks for a new foo to be created to the given subnet with the specific bar named
/// </summary>
/// <param name="fooData"></param>
/// <returns></returns>
[Route("newFoo/")]
public async Task<IHttpActionResult> PostNewFooForSpecificBar(FooRequestObject fooData)
{
}
}
并在 FooRequestObject 中包含我需要的所有数据