How to use html file in asp. net core project
- 2021-10-16 01:26:29
- OfStack
Preface
As you should know, in the asp. net core project, services are provided using middleware like html File 1:
Open the NuGet Program Management Console
Input
install-package Microsoft.aspnetcore.staticfiles
Adding
ASP.NET Core static files middleware. Includes middleware for serving static files, directory browsing, and default files
.
Using services 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 https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseStaticFiles();
app.UseMvc();
}
}
}
Add Baidu. html under wwwroot
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Baidu</title>
</head>
<body>
<a href="http://www.baidu.com" target="_self"><em> Enter Baidu </em></a>
</body>
</html>
Modify Index. cshtml to add access links
@page
@model MyWeb.Pages.IndexModel
@{
ViewData["Title"] = "Index";
}
<h2>Index</h2>
<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 on Index home page
Or enter the address http://localhost: port number/Baidu. html
Summarize