SoFunction
Updated on 2025-04-11

How to use html files in core project

Preface

Everyone should know that in core projects, using html files is generally used to provide services by using middleware:

Open the NuGet Program Management Console

enterinstall-package Make an addition

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

Use the service in:

using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
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 /fwlink/?LinkID=398940
    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 under wwwroot

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>Baidu</title>
</head>
<body>
  <a href="" target="_self"><em>Enter Baidu</em></a>
</body>
</html>

Modify, add access link

@page
@model 
@{
  ViewData["Title"] = "Index";
}

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

Run MyWeb to access it on the Index homepage

Or enter the address http://localhost:port number/

Summarize

The above is the entire content of this article. I hope that the content of this article has a certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.