Home > Mobile >  How To deploy asp.net core web api project with react(standalone) in visual studio 2022
How To deploy asp.net core web api project with react(standalone) in visual studio 2022

Time:09-21

I just follow enter image description here

The index file:

enter image description here

Browse WebSite :

enter image description here

and the result :

enter image description here

And the postman for test api that was Success :

enter image description here

CodePudding user response:

In short, you don't need to deploy separately. Of course, you can deploy them separately if you need them.

We can see from the .csproj file what actions were done when it was released, and the project of the react front-end was placed under wwwroot, so the project under wwwroot can be deployed separately or directly from the deployed asp.net core project.

enter image description here

enter image description here

CodePudding user response:

I changed program.cs to below and it worked!

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();

app.UseAuthorization();

//app.MapControllers();
app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();

    // route non-api urls to index.html
    endpoints.MapFallbackToFile("/index.html");
});

app.Run();
  • Related