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

查看:50
本文介绍了.net核心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核心api为每个请求返回客户端index.html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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