.net core api 为每个请求返回客户端 index.html 文件 [英] .net core api returns clients index.html file for every request

查看:31
本文介绍了.net core api 为每个请求返回客户端 index.html 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 dotnet new reactredux 命令设置了 reactredux/dotnetcore 应用程序.我正在尝试测试我的 api,但是每当我尝试获取某些东西时,我唯一返回的就是来自 react 客户端的 index.html.即使对于我没有指定的端点.

I setup a reactredux/dotnetcore app with the dotnet new reactredux command. I'm trying to test my api but whenever I try to fetch something, the only thing I get back is the index.html from the react client. Even for endpoints I have not specified.

我的应用程序在 localhost 5000 和 5001 上运行,两者都得到相同的结果.

I have my app running on localhost 5000 and 5001 and for both I get the same result.

我是不是忘记设置一些设置了?
我是否使用了错误的地址?我在哪里可以找到合适的.

Did I forget to set some setting?
Am I using the wrong address? Where can I find the right one.

推荐答案

只要 MVC 后端没有匹配的请求路由,ASP.NET Core SPA 模板就会将您重定向到 SPA index.html 静态页面.将此控制器添加到您的应用程序,看看您是否可以从它获得响应.如果可行,请将更改与您正在调用的其他控制器进行比较:

ASP.NET Core SPA templates will redirect you to the SPA index.html static page whenever the MVC backend doesn't have a matching route for the request. Add this controller to your application and see if you can get a response from it. If it works compare the changes to the rest of the controllers you're calling:

[Route("api/[controller]")]
public class TestController : ControllerBase
{
    [Route("[action]")]
    public IActionResult Test() => Content("Hello World!");
}

这篇关于.net core api 为每个请求返回客户端 index.html 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆