I have an asp.net core and react project and I publish it to the IIS server. But after deploying it, it showed 'page can't be found' error. And when I added /index.html to the url (www.mywebsite.com/index.html), it showed my website and it seemed to be functioning.
Also, there's no wwwroot folder in my project and the wwwroot folder will be created on the IIS server when I publish the project.
Obviously, I don't want the user to enter /index.html when they access my website. I followed this tutorial but it didn't work https://dotnettutorials.net/lesson/configuring-default-page-asp-net-core/ .
Can anyone help me with that? Thanks!
Here's my program.cs file:
using Microsoft.EntityFrameworkCore;
using PslProcEng.Data;
using Microsoft.AspNetCore.Mvc.NewtonsoftJson;
using Microsoft.AspNetCore.Authentication.Negotiate;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.FileProviders;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHttpContextAccessor();
builder.Services.AddControllers();
builder.Services.AddControllersWithViews();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddDbContext<Context>(o => o.UseSqlServer(builder.Configuration.GetConnectionString("Connection")));
builder.Services.AddControllers().AddNewtonsoftJson();
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
.AddNegotiate();
builder.Services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseDefaultFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(
AppDomain.CurrentDomain.BaseDirectory)),
});
app.UseRouting();
app.MapControllers();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
app.MapFallbackToFile("index.html");
app.Run();