把网页(例如index.html)放在wwwroot下(一定要放在wwwroot下),然后在Startup.cs文件的 public void Configure(IApplicationBuilder app, IHostingEnvironment env) 方法里添加下面两种方法中的一种即可
//1
DefaultFilesOptions defaultFilesOptions = new DefaultFilesOptions();
defaultFilesOptions.DefaultFileNames.Clear();
defaultFilesOptions.DefaultFileNames.Add("index.html");
app.UseDefaultFiles(defaultFilesOptions);
app.UseStaticFiles();
//或者
//2
FileServerOptions fileServerOptions = new FileServerOptions();
fileServerOptions.DefaultFilesOptions.DefaultFileNames.Clear();
fileServerOptions.DefaultFilesOptions.DefaultFileNames.Add("index.html");
app.UseFileServer(fileServerOptions);