Skip to content

Instantly share code, notes, and snippets.

@nishanc
Created February 13, 2024 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishanc/6dc687fc063eec176d9e1c50abff7108 to your computer and use it in GitHub Desktop.
Save nishanc/6dc687fc063eec176d9e1c50abff7108 to your computer and use it in GitHub Desktop.
using Microsoft.Extensions.FileProviders;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
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();
var fileProvider = new PhysicalFileProvider(
Path.Combine(app.Environment.WebRootPath, "Portal.App"));
app.UseDefaultFiles(new DefaultFilesOptions
{
FileProvider = fileProvider,
RequestPath = "",
DefaultFileNames = new[] { "index.html" }
});
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = fileProvider,
RequestPath = ""
});
app.UseRouting();
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
app.MapFallbackToFile("index.html", new StaticFileOptions
{
FileProvider = fileProvider,
RequestPath = ""
});
app.Run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment