繁体   English   中英

如何在ASP.NET 5中提供静态页面并将用户重定向到该页面?

[英]How do I serve a static page in ASP.NET 5 and redirect users to it?

我正在尝试使用ASP.NET Web Application > empty .net 5模板创建AngularJS应用ASP.NET Web Application 但是现在我正在尝试构建事物,并且总是显示Hello World

因此,我开始进行挖掘,发现这是因为Startup.cs仅返回了它;

但是现在我要制作它,以便它重定向到/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);
    }
}

通过此Configure实现,您将静态提供index.html:

public void Configure(IApplicationBuilder app)
{        
   app.UseStaticFiles();
   app.UseDefaultFiles(new Microsoft.AspNet.StaticFiles.DefaultFilesOptions() { DefaultFileNames = new[] { "index.html" } });          
}

有关此文档,请参见此处 实际上也不需要DefaultFilesOptions,因为index.html仍然在默认列表中。

对不起,我的上一篇文章...这确实是一个糟糕的解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM