How to Use html files in asp.net core projects,

Source: Internet
Author: User

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.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 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.