您现在的位置是:网站首页> 编程资料编程资料
asp.net core项目中如何使用html文件_实用技巧_
2023-05-24
360人已围观
简介 asp.net core项目中如何使用html文件_实用技巧_
前言
大家应该都知道,在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
Baidu 进入百度
修改Index.cshtml,添加访问链接
@page @model MyWeb.Pages.IndexModel @{ ViewData["Title"] = "Index"; } Index
Index2Baidu
CustomersIndexHello, world!
The time on the server is @DateTime.Now
运行MyWeb在Index首页进行访问
或者输入地址http://localhost:端口号/Baidu.html
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对的支持。
您可能感兴趣的文章:
- 详解ASP.NET Core WebApi 返回统一格式参数
- ASP.NET Core DI手动获取注入对象的方法
- ASP.NET Core2读写InfluxDB时序数据库的方法教程
- ASP.NET Core使用自定义验证属性控制访问权限详解
- ASP.NET Core Mvc中空返回值的处理方法详解
- asp.net core集成MongoDB的完整步骤
- Asp.NET Core 如何调用WebService的方法
- ASP.NET Core Web App应用第三方Bootstrap模板的方法教程
- Centos7+Docker+Jenkins+ASP.NET Core 2.0自动化发布与部署的实现
- 浅谈从ASP.NET Core2.2到3.0你可能会遇到这些问题
相关内容
- .NET Core 实现定时抓取网站文章并发送到邮箱_实用技巧_
- 详解Asp.net web.config customErrors 如何设置_实用技巧_
- XAML: 自定义控件中事件处理的最佳实践方法_实用技巧_
- ASP.NET没有魔法_ASP.NET MVC 模型验证方法_实用技巧_
- .Net Core部署到CentOS的图文教程_实用技巧_
- .net Core连接MongoDB数据库的步骤详解_实用技巧_
- ASP.NET Core缓存静态资源示例详解_实用技巧_
- mysql安装后.net程序运行出错的解决方法_实用技巧_
- ASP.NET Core 2.0中Razor页面禁用防伪令牌验证_实用技巧_
- .NET中OpenFileDialog使用线程报错的解决方法_实用技巧_
