[英]How to view content of HTML-CSS on an Empty ASP.NET Core Web application
我剛剛開始對ASP.NET Core以及整個Web開發(HTML和CSS)感到滿意。
我使用空模板創建了新的ASP.NET Core Web應用程序,並添加了兩個簡單的HTML文件-Index.html和Menu.html。 運行調試時,除默認的“ Hello World”外,看不到其他任何內容。
在此過程中我會錯過任何事情嗎?
對於Html-Css
,它們是靜態文件,您需要通過app.UseStaticFiles();
啟用StaticFile Middleware app.UseStaticFiles();
。
請嘗試以下步驟:
修改Startup.cs
以添加app.UseStaticFiles();
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) { } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStaticFiles(); app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); }); } }
通過輸入https://localhost:44387/index.html
啟動項目並訪問您的靜態文件
此外,您可以通過ASP.NET Core簡介熟悉asp.net core。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.