We have an area on our site where people can register and get their own page on the site that we want to place in ~ / pageSlug. I tried to do this using a rule in Global.asax, but this violated the default default route, which allows ~ / Controller to directly map the index action. I am not allowed to put any separator in front of userSlug, so ~ / p / pageSlug is actually not an option.
Regarding adding custom pages to routes, I look at the pages in App_Start and explicitly add them to RoutesTable. This works fine, and we have AppPool updates installed long enough to do it once a day. This leaves us with a 24-hour turn to “get pages live” for our users, although I'm trying to solve it.
Ideally, what I would like to do is add the appropriate route to RouteTable dynamically after the user has registered. I tried to do this with:
RouteTable.Routes.Add(
RouteTable.Routes.MapRoute(
toAdd.UrlSlug + "Homepage",
toAdd.UrlSlug,
new { controller = "Controller", View = "View", urlSlug = toAdd.UrlSlug }
)
);
but that didn't seem to work. I can’t find a solution anywhere, and I’m sure that my code is terribly naive and betrays a lack of understanding of routing - please help!
source
share