如果我取消注释代码的app.Run(async (context) => ...
部分,我可以在代码中运行html而不会出现任何问题。我试图使用wwwroot中的index.html作为默认值。但是我收到404错误。我该如何解决这个问题?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.DependencyInjection;
namespace TheWorld
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app)
{
// app.Run(async (context) =>
//{
// var link = @"<!DOCTYPE html>
// <html>
// <head>
// <title>test</title>
// </head>
// <body>
// <h1>TestFile</h1>
// </body>
// </html>";
// await context.Response.WriteAsync(link);
//});
}
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup> (args);
}
}
答案 0 :(得分:0)
您可以使用Nuget-package Microsoft.Owin.StaticFiles
,然后Configure
中的第一件事就是这样写:
app.UseDefaultFiles(new DefaultFilesOptions
{
DefaultFileNames = new List<string>() { "index.html" }
});