asp.netcore项目中使用html文件的方法-创新互联

这篇文章将为大家详细讲解有关asp.net core项目中使用html文件的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

创新互联公司专业为企业提供安定网站建设、安定做网站、安定网站设计、安定网站制作等企业网站建设、网页设计与制作、安定企业网站模板建站服务,10多年安定做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

前言

在asp.net core 项目中,使用html文件一般通过使用中间件来提供服务:

打开 NuGet程序管理控制台

输入install-package Microsoft.aspnetcore.staticfiles 进行添加

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

在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 /tupian/20230522/startup
    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();
    }
  }
}

在wwwroot下添加Baidu.html




  
  Baidu


  进入百度

修改Index.cshtml,添加访问链接

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

Index

Index2 Baidu CustomersIndex

Hello, world!

The time on the server is @DateTime.Now

运行MyWeb在Index首页进行访问

或者输入地址http://localhost:端口号/Baidu.html

关于“asp.net core项目中使用html文件的方法”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。


新闻名称:asp.netcore项目中使用html文件的方法-创新互联
标题URL:http://pwwzsj.com/article/dsphpj.html