How to Use html files in asp.net core projects,
Preface
Everyone should know that in the asp.net core project, html files are generally used to provide services through middleware:
Open the NuGet program Console
Inputinstall-package Microsoft.aspnetcore.staticfiles
Add
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 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(); } }}
Upload baidu.html under wwwroot
<! DOCTYPE html>
Modify Index. cshtml and add an access Link
@page@model MyWeb.Pages.IndexModel@{ ViewData["Title"] = "Index";}
Run MyWeb to access the Index homepage.
Or enter the http: // localhost: Port Number/Baidu.html
Summary
The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.