Invoke same action for all urls in ASP.NET Core MVC

拟墨画扇 提交于 2019-12-24 12:23:02

问题


I am creating a single page app in the new ASP 5. How can I tell it to always server Home/Index no matter what (unless the request has wwwroot in the path)?

More specifically, I would like something like this:

app.UseStaticFiles();
app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "Home/Index/");
            });

where first it searches the static files and then it if none are found, it just serves up Home/Index


回答1:


How about a catch-all route?

app.UseStaticFiles();
app.UseMvc(routes =>
{
     routes.MapRoute(
          name: "default",
          template: "{*url}",
          defaults: new { controller = "Home", action = "Index" });
});


来源:https://stackoverflow.com/questions/35926027/invoke-same-action-for-all-urls-in-asp-net-core-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!