[英]How do I serve a static page in ASP.NET 5 and redirect users to it?
I'm trying to create AngularJS app with the ASP.NET Web Application
> empty .net 5
template. 我正在尝试使用ASP.NET Web Application
> empty .net 5
模板创建AngularJS应用ASP.NET Web Application
。 But now I'm trying to build the thing and it's always showing Hello World
但是现在我正在尝试构建事物,并且总是显示Hello World
So I started digging, and found that it was because the Startup.cs
just returns that; 因此,我开始进行挖掘,发现这是因为Startup.cs
仅返回了它;
but now I want to make it so it redirects to the /wwwroot/index.html
this is the startup file: 但是现在我要制作它,以便它重定向到/wwwroot/index.html
这是启动文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.DependencyInjection;
namespace WebTemplate
{
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 http://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)
{
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);
}
}
With this Configure implementation you will serve index.html statically: 通过此Configure实现,您将静态提供index.html:
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
app.UseDefaultFiles(new Microsoft.AspNet.StaticFiles.DefaultFilesOptions() { DefaultFileNames = new[] { "index.html" } });
}
The documentation for this is here . 有关此文档,请参见此处 。 The DefaultFilesOptions is actually also not needed since index.html is in the default list anyway. 实际上也不需要DefaultFilesOptions,因为index.html仍然在默认列表中。
Sorry for my last post... that was really a bad solution. 对不起,我的上一篇文章...这确实是一个糟糕的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.