分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

asp.net core 使用html文件

发布时间:2023-09-06 01:43责任编辑:熊小新关键词:暂无标签

在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中使用服务:

 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Threading.Tasks; 5 using Microsoft.AspNetCore.Builder; 6 using Microsoft.AspNetCore.Hosting; 7 using Microsoft.AspNetCore.Http; 8 using Microsoft.Extensions.DependencyInjection; 9 10 namespace MyWeb11 {12 ????public class Startup13 ????{14 ????????// This method gets called by the runtime. Use this method to add services to the container.15 ????????// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=39894016 ????????public void ConfigureServices(IServiceCollection services)17 ????????{18 ????????????services.AddMvc();19 ????????}20 21 ????????// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.22 ????????public void Configure(IApplicationBuilder app, IHostingEnvironment env)23 ????????{24 ????????????app.UseStaticFiles();25 ????????????app.UseMvc();26 ????????}27 ????}28 }

在wwwroot下添加Baidu.html

 1 <!DOCTYPE html> 2 <html> 3 <head> 4 ????<meta charset="utf-8" /> 5 ????<title>Baidu</title> 6 </head> 7 <body> 8 ????<a href="http://www.baidu.com" target="_self"><em>进入百度</em></a> 9 </body>10 </html>

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

 1 @page 2 @model MyWeb.Pages.IndexModel 3 @{ 4 ????ViewData["Title"] = "Index"; 5 } 6 ?7 <h2>Index</h2> 8 <a href="Index2">Index2</a> 9 <a href="Baidu.html" target="_self">Baidu</a>10 <hr />11 <a href="Customers">CustomersIndex</a>12 <h1>Hello, world!</h1>13 <h2>The time on the server is @DateTime.Now</h2>

运行MyWeb在Index首页进行访问

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

asp.net core 使用html文件

原文地址:https://www.cnblogs.com/szz-55555/p/8461489.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved