【发布时间】:2015-11-27 07:21:39
【问题描述】:
我正在探索 ASP。 NET 5 并遵循一些教程。
我正在使用 Visual Studio 2015。
我打开了项目>ASP NET Web 应用程序>ASP NET 5 模板>空。
我做了一个简单的构建,它显示“Hello World”
所以我在 wwwroot 目录中添加了 index.html
并注释掉 startup.cs 代码中的 hello world 行
public class Startup
{
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)
{
// app.UseIISPlatformHandler();
// app.Run(async (context) =>
// {
// await context.Response.WriteAsync("Hello World");
// });
}
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
现在,当我构建和运行时,我得到一个空白屏幕。它应该显示 index.html 但事实并非如此。
编辑:使用 app.UseStaticFiles();仅适用于 /index.html 而不是一般情况。
回答:我发现所有的 ASPNET 测试版都有 app.UseStaticFiles();为静态文件服务。现在 1.0.0-rc1-final 发布了,我们必须使用 app.UseDefaultFiles(); 以及
【问题讨论】:
-
你想使用 MVC 显示 Hello world 吗?
-
index.Html 上有什么要显示的吗?
-
是的 index.html 有基本的正文和文本。不,不使用 MVC。到目前为止,只是为了显示一个静态文件。 (稍后我会做 MVC)
标签: c# asp.net asp.net-mvc asp.net-core