---
# System prepended metadata

title: '`ASP.NET Core` のトップページで、`index.html` を表示する 2023-03-05'
tags: [index.html, ASP.NET Core, Blazor]

---

---
lang: ja-jp
breaks: true
---
# `ASP.NET Core` のトップページで、`index.html` を表示する 2023-03-05

> 既定のドキュメントの提供
> https://learn.microsoft.com/ja-jp/aspnet/core/fundamentals/static-files?view=aspnetcore-7.0#serve-default-documents

## 以下を追加する

```csharp=
var opt = new DefaultFilesOptions();
opt.DefaultFileNames.Clear();
opt.DefaultFileNames.Add("index.html");
app.UseDefaultFiles(opt);
```

## Blazor Server の場合の例

```csharp=
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();

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();

var opt = new DefaultFilesOptions();
opt.DefaultFileNames.Clear();
opt.DefaultFileNames.Add("index.html");
app.UseDefaultFiles(opt);

app.UseStaticFiles();

app.UseRouting();

app.MapBlazorHub();
//app.MapFallbackToPage("/_Host");

app.Run();
```

###### tags: `ASP.NET Core` `index.html` `Blazor`
