前言
大家应该都知道,在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 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(); } } }
在wwwroot下添加Baidu.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Baidu</title> </head> <body> <a href="http://www.baidu.com" target="_self"><em>进入百度</em></a> </body> </html>
修改Index.cshtml,添加访问链接
@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>
运行MyWeb在Index首页进行访问
或者输入地址http://localhost:端口号/Baidu.html
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对站长技术的支持。
1.准备工作 1.1PHP集成环境 这里我们使用的是XAMPP,XAMPP是一个功能强大的建站...
因为想自己写一个web,所以也在学习html语言的一些东西,让我回想起了大学时代曾对...
方案一 自定义yaml文件安装redis cluster 背景 在Kubernetes中部署Redis集群面临...
cannot be cast to javax.servlet.Filter 报错, 原因servlet-api.jar冲突 使用ma...
前言: 我们在实际项目开发中,经常会遇到一些不可预见的异常产生,有的异常在程...
关于开源工具与专有工具的争论早已不是什么新鲜事。但在AIOps工具方面,还有其他...
前几天,GitHub 有个开源项目特别火,只要输入标题就可以生成一篇长长的文章。 ...
今天,微软宣布Windows 10 Version 2004功能更新现在已经添加到广泛部署(broad d...
寸为xml查看效果 WEB标准网站设计心得 - http://blog.donews.com/dodo/category/...
前言 在 Net Core 2.2 中,官方文档表示,对 EventListener 这个日志监视类的内...