屌丝小宝,黄山汽车站,校园笑话大全
前言
大家应该都知道,在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
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对移动技术网的支持。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论