Area and subdomain routing

前端 未结 5 849
遇见更好的自我
遇见更好的自我 2021-01-06 09:34

I created Admin Area inside my ASP.NET Core application and updated my routes like that:

app.UseMvc(routes =>
{
    routes.MapRoute(name: \"areaRoute\",
          


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-06 09:48

    Good solution Sergio was able to create the subdomain routing. Just to add to your solution and to complete the subdomain route to the physical directory.

        public class HomeController : Controller
        {
            public async Task Index(int? id, string subdomain)
            {
                 if (!string.IsNullOrWhiteSpace(subdomain))
                 {
                    if(subdomain=="admin")
                    return View("~/wwwrootadmin/index.cshtml");
                 }
                 return View("~/wwwroot/index.cshtml");
            }
        }
    

    Then wwwrootadmin has to be created with your files for the subdomain. Remember the order of route order matters inside the app.UseMvc()

提交回复
热议问题