小编Fer*_*o C的帖子

ASP.NET Core - React:无法将请求代理到 http://localhost:3000/,因为对代理目标的请求失败

我正在使用 ASP.NET Core 和 ReactJS 开发一个网站。

开发时,我在运行应用程序的本地计算机上没有遇到任何问题,但是,当尝试在服务器上部署时,使用模板提供的默认 SPA 代码无法正常工作,因为网站给出了以下错误:

HttpRequestException:无法建立连接,因为目标机器主动拒绝。(本地主机:3000)

我已经看到如果使用可以解决该错误,spa.UseProxyToSpaDevelopmentServer("http://localhost:xxxx/")但它不起作用。

我的Startup.cs样子如下:

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddCors();

        services.AddDbContext<ApplicationDbContext>(options =>
        {
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
        });

        //services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
        //    .AddEntityFrameworkStores<ApplicationDbContext>();

        services.AddIdentity<ApplicationUser, IdentityRole>()
            .AddRoleManager<RoleManager<IdentityRole>>()
            .AddDefaultUI()
            .AddDefaultTokenProviders()
            .AddEntityFrameworkStores<ApplicationDbContext>();

        services.AddIdentityServer()
            .AddApiAuthorization<ApplicationUser, ApplicationDbContext>();

        services.AddAuthentication()
            .AddIdentityServerJwt(); …
Run Code Online (Sandbox Code Playgroud)

asp.net deployment reactjs asp.net-core

5
推荐指数
1
解决办法
8627
查看次数

标签 统计

asp.net ×1

asp.net-core ×1

deployment ×1

reactjs ×1