I'm trying to implement multi tenancy based on the first folder segment of the request url.
Consider the following fragments from my startup.
foreach (SiteFolder f in allFolders)
{
PathString path = new PathString("/" + f.FolderName);
app.Map(path,
siteApp =>
{
//here I'm trying to specify a different auth cookie name for folder sites and some other configuration
// but problem happens even with no code here at all
// I also tried adding the folder specific routes here but still 404
});
}
app.UseMvc(routes =>
{
List<SiteFolder> allFolders = siteRepo.GetAllSiteFoldersNonAsync();
foreach (SiteFolder f in allFolders)
{
routes.MapRoute(
name: f.FolderName + "Default",
template: f.FolderName + "/{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" },
constraints: new { name = new SiteFolderRouteConstraint(f.FolderName) }
);
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
If I comment out app.Map at the top then my routes work as expected but otherwise if I have branching on the same folder names as as in my folder routes, the folder urls all result in an IIS 404 page.
I thought maybe siteApp doesn't see the routes added to app so I tried adding the routes to siteApp but it still resulted in 404.
A similar approach worked for me in MVC 5, I feel like either there is a bug in the framework (beta5) or I'm missing some important concept about branching and the new framework.