How to use HTML file in core project



You should all know that in core project, HTML files are generally used to provide services by using middleware:

Open nuget program management console

inputinstall-package Microsoft.aspnetcore.staticfilesAdd

ASP.NET Core static files middleware. Includes middleware for serving static files, directory browsing, and default files.

Use the service in startup.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace MyWeb
  public class Startup
    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit
    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, IHostingEnvironment env)

Add baidu.html under wwwroot

<!DOCTYPE html>
  <meta charset="utf-8" />
  < a href = "" target = "self" > < EM > Enter Baidu < / EM ></a>

Modify index.cshtml and add access link

@model MyWeb.Pages.IndexModel
  ViewData["Title"] = "Index";

<a href="Index2">Index2</a>
<a href="Baidu.html" target="_self">Baidu</a>
<hr />
<a href="Customers">CustomersIndex</a>
<h1>Hello, world!</h1>
<h2>The time on the server is @DateTime.Now</h2>

Run myweb to access the index Homepage

Or enter the address http://localhost: port number / baidu.html


The above is the whole content of this article. I hope that the content of this article has a certain reference learning value for everyone’s study or work. If you have any questions, you can leave a message and exchange. Thank you for your support for developepaar.