简体   繁体   English

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

[英]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.

相关问题 如何使用ASP.NET重定向到另一个页面? - How do I redirect to another page with ASP.NET? 您如何在 ASP.NET 中与 SPA 静态文件一起提供“普通”静态文件? - How do you serve “normal” static files alongside SPA static files in ASP.NET? 我如何从asp.net(aspx)页面枚举静态类中包含的静态字典 - How do I enumerate a static dictionary contained in a static class from asp.net ( aspx) page 如何从Silverlight应用程序内重定向包含Silverlight应用程序的asp.net页面? - How do I redirect the asp.net page that contains a silverlight app from within the silverlight app? 如何在页面重定向后发布消息以确认已发送的消息(C#/ ASP.Net) - How do I post a message to confirm a sent message after a page redirect (C#/ASP.Net) 如何使用 Z686155AF75A60A0EDD3F6E9D80C1 从 ASP.NET Controller 重定向到另一个 web 页面? - How do I redirect to another web page from an ASP.NET Controller using JavaScript? ASP.NET Razor 页面 - 如果用户尝试访问无效的 URL,我该如何重定向用户? - ASP.NET Razor Page - How do I redirect user if they try to access invalid URL? 我如何将 Console.Write 重定向到 asp.net 网页的 TextBox。有什么办法吗? - How do i Redirect Console.Write to TextBox of asp.net web page.Is there any way? 如何在ASP.NET中从RadPane重定向到另一个页面? - How do I redirect to another page from RadPane in ASP.NET? 如何从Javascript在ASP.Net页面上调用静态方法? - How do I call a static method on my ASP.Net page, from Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM