404错误Localhost:8000 asp.Net

时间:2016-04-22 02:23:47

标签: c# asp.net asp.net5

如果我取消注释代码的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);
    }
}

1 个答案:

答案 0 :(得分:0)

您可以使用Nuget-package Microsoft.Owin.StaticFiles,然后Configure中的第一件事就是这样写:

    app.UseDefaultFiles(new DefaultFilesOptions
    {
        DefaultFileNames = new List<string>() { "index.html" }
    });
相关问题