2018年8月24日 星期五

【ASP.NET Core 2】修改預設網頁

ASP.NET Core 2 預設的靜態頁面為index
若想變更預設的載入頁面
可在 Startup.cs 加入以下程式


public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseBrowserLink();
        app.UseDeveloperExceptionPage();
    }
    else
    {
        app.UseExceptionHandler("/Error");
    }


    app.Use(async (context, next) => {
        await next();

        if (context.Response.StatusCode == 404 &&
            !System.IO.Path.HasExtension(context.Request.Path.Value) &&
            !context.Request.Path.Value.StartsWith("/api/"))
        {
            context.Request.Path = "/ming";

            await next();
        }
    });


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



    app.UseMvc();
}

沒有留言:

張貼留言