.NET Core rc2 WebAPI,index.html为默认页面

hho*_*tij 1 asp.net-core

我已经设置了一个空的WebAPI项目.NET Core rc2并将其连接起来Angular2 rc1.Angular将处理所有相关视图,WebAPI是后端.

当我默认启动应用程序时,它会localhost:4578/api/values从默认的API控制器中作为startpage启动.

但是,我希望它index.html默认显示位于wwwroot我的Angular2应用程序并托管我的应用程序.

Startup.csConfigure方法中看起来像这样:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddDebug();

        app.UseDefaultFiles();
        app.UseStaticFiles();
        app.UseMvc();

        app.Run(ctx =>
        {
            ctx.Response.Redirect("/index.html");
            return Task.FromResult(0);
        });
    }
Run Code Online (Sandbox Code Playgroud)

app.UseStaticFiles并且app.Runlambda需要到位以便手动重定向index.html才能工作,但它仍然是/api/values默认的起始页面.

我知道出于调试目的,我可以轻松地更改起始页面,但我想更改它,以便在我托管它时它始终用作index.html起始页面.

我怎么能改变这个?

小智 10

创建新的空WebAPI项目时,launchsettings.json文件默认指向api/values.要更改它,请转到项目中的launchsettings.json文件:

在此输入图像描述

并将launchUrl值更改为:http:// localhost:4578(来自http:// localhost:4578/api/values).