asp.net core项目中如何使用html文件
前言
大家应该都知道,在asp.netcore项目中,使用html文件一般通过使用中间件来提供服务:
打开NuGet程序管理控制台
输入install-packageMicrosoft.aspnetcore.staticfiles进行添加
ASP.NETCorestaticfilesmiddleware.Includesmiddlewareforservingstaticfiles,directorybrowsing,anddefaultfiles.
在Startup.cs中使用服务:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Threading.Tasks;
usingMicrosoft.AspNetCore.Builder;
usingMicrosoft.AspNetCore.Hosting;
usingMicrosoft.AspNetCore.Http;
usingMicrosoft.Extensions.DependencyInjection;
namespaceMyWeb
{
publicclassStartup
{
//Thismethodgetscalledbytheruntime.Usethismethodtoaddservicestothecontainer.
//Formoreinformationonhowtoconfigureyourapplication,visithttps://go.microsoft.com/fwlink/?LinkID=398940
publicvoidConfigureServices(IServiceCollectionservices)
{
services.AddMvc();
}
//Thismethodgetscalledbytheruntime.UsethismethodtoconfiguretheHTTPrequestpipeline.
publicvoidConfigure(IApplicationBuilderapp,IHostingEnvironmentenv)
{
app.UseStaticFiles();
app.UseMvc();
}
}
}
在wwwroot下添加Baidu.html
Baidu 进入百度
修改Index.cshtml,添加访问链接
@page
@modelMyWeb.Pages.IndexModel
@{
ViewData["Title"]="Index";
}
Index
Index2
Baidu
CustomersIndex
Hello,world!
Thetimeontheserveris@DateTime.Now
运行MyWeb在Index首页进行访问
或者输入地址http://localhost:端口号/Baidu.html
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对毛票票的支持。