【问题标题】:.net core api returns clients index.html file for every request.net core api 为每个请求返回客户端 index.html 文件
【发布时间】:2018-12-09 06:17:35
【问题描述】:
我使用 dotnet new reactredux 命令设置了一个 reactredux/dotnetcore 应用程序。我正在尝试测试我的 api,但是每当我尝试获取某些东西时,我唯一得到的就是来自 react 客户端的 index.html。即使对于我没有指定的端点。
我的应用程序在 localhost 5000 和 5001 上运行,对于两者我得到相同的结果。
我是否忘记设置一些设置?
我使用了错误的地址吗?我在哪里可以找到合适的。
【问题讨论】:
标签:
c#
.net
api
react-redux
【解决方案1】:
只要 MVC 后端没有匹配的请求路由,ASP.NET Core SPA 模板就会将您重定向到 SPA index.html 静态页面。将此控制器添加到您的应用程序中,看看您是否可以从中获得响应。如果可行,请将更改与您调用的其他控制器进行比较:
[Route("api/[controller]")]
public class TestController : ControllerBase
{
[Route("[action]")]
public IActionResult Test() => Content("Hello World!");
}