asp.net core项目中如何使用html文件
2018-02-25 08:23
751 查看
前言
大家应该都知道,在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
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。
您可能感兴趣的文章:
相关文章推荐
- 项目开发中的一些注意事项以及技巧总结 基于Repository模式设计项目架构—你可以参考的项目架构设计 Asp.Net Core中使用RSA加密 EF Core中的多对多映射如何实现? asp.net core下的如何给网站做安全设置 获取服务端https证书 Js异常捕获
- 如何使用,ASP.Net,将Word,转换为,HTML文件,教程实例
- ASP.NET Core 中文文档 第四章 MVC(3.4)如何使用表单
- 在Mac上开发使用yoeman构建Asp.net core项目并且实现分层引用
- 如何使用asp.net自带的缓存优化我们的项目?
- Sharepoint online 如何使用asp.net开发项目!!!
- 在win 2008 R2环境下如何使用iis7.0正确发布ASP。NET项目
- Asp.Net Core 项目搭建 基础配置 和MySql 的使用
- [C#] .NET Core/Standard 1.X 项目中如何使用XmlIgnoreAttribute等标准范围外的内容,兼谈如何解决“violation of security transparency rules failed”(违反安全透明规则失败)异常
- ASP.NET Core中的缓存[1]:如何在一个ASP.NET Core应用中使用缓存
- Asp.Net Core 项目实战之权限管理系统(3) 通过EntityFramework Core使用PostgreSQL
- 如何使用 asp.net 4.0 新特性 路由功能 有助于seo优化 给一个 asp.net web项目(网站项目) 增加路由功能 ,继承,给根据路由生成的url的结尾,增加一个有利于seo优化的斜杠 /,跳转到一个路由生成的url页面
- 如何在ASP.NET项目里面正确使用Linq to Sql
- 如何使用ASP.NET Core实现搜索功能
- 如何在ASP.NET Core中使用Redis
- 如何在ASP.NET项目里面正确使用Linq to Sql
- 在win 2008 R2环境下如何使用iis7.0正确发布ASP。NET项目
- ASP.NET项目开发中日期控件DatePicker如何使用
- 如何在ASP.NET 网站项目中使用C# 6?
- 艾伟:如何在ASP.NET项目里面正确使用Linq to Sql