【发布时间】:2019-05-30 00:30:20
【问题描述】:
我在 ASP.NET Core Web api 中遇到 url 路由问题。当 URL 连续点 (.) 时,它返回 404 not found。例如,
不适用于电子邮件但不带点的代码
public class TestController : Controller{
{
[HttpGet]
[Route("{id:int}")]
public IActionResult Get(int id)
{
//whatever
}
[HttpGet]
[Route("{id:int}/{name:alpha}")]
public IActionResult Get(int id, string name)
{
//whatever
}
}
但是,这行得通
public class TestController : Controller{
{
[HttpGet("GetById/{id}")]
public IActionResult Get(int id)
{
//whatever
}
[HttpGet("GetByName/{id}/{name}")]
public IActionResult Get(int id, string name)
{
//whatever
}
}
如何解决这个问题?
【问题讨论】:
-
fake@email.com无论如何都是无效的。您是否忘记对@进行url 编码? urlencoder.org -
@没问题。问题是点 (.)。我正在使用 IIS 8.5
-
它可能工作,但你不应该这样传递
@。你应该对它进行 url 编码。
标签: c# asp.net-core asp.net-core-webapi