這篇文章將為大家詳細(xì)講解有關(guān)asp.net core項(xiàng)目中使用html文件的方法,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
前言
在asp.net core 項(xiàng)目中,使用html文件一般通過使用中間件來提供服務(wù):
打開 NuGet程序管理控制臺
輸入install-package Microsoft.aspnetcore.staticfiles
進(jìn)行添加
ASP.NET Core static files middleware. Includes middleware for serving static files, directory browsing, and default files
.
在Startup.cs中使用服務(wù):
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 /tupian/20230522/startup 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 進(jìn)入百度
修改Index.cshtml,添加訪問鏈接
@page @model MyWeb.Pages.IndexModel @{ ViewData["Title"] = "Index"; }Index
Index2 Baidu
CustomersIndexHello, world!
The time on the server is @DateTime.Now
運(yùn)行MyWeb在Index首頁進(jìn)行訪問
或者輸入地址http://localhost:端口號/Baidu.html
關(guān)于“asp.net core項(xiàng)目中使用html文件的方法”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯(cuò),請把它分享出去讓更多的人看到。