我刚开始接触 ASP.NET Core和Web开发(HTML和CSS(。
我使用空模板创建了一个新的 ASP.NET 核心 Web 应用程序,并添加了两个简单的 HTML 文件 - 索引.html 和 Menu.html。当我运行调试时,除了默认的"Hello World"之外,我看不到任何其他内容。
我在这个过程中错过了什么吗?
对于Html-Css
来说,它们是静态文件,你需要通过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 核心简介中熟悉 asp.net 核心