Using asp.net core MVC application here. I have my areas defined and routing works as expected.
One thing i would like to do, is have a fallback route in case the area does not exist.
I have the following structure:
APP
-- Areas
-- SharedArea
-- Controllers
-- LoginController
-- UserController
-- AnotherController
-- AndSoOnController
-- SomeArea1
-- Controllers
-- HomeController
-- SomeArea2
-- Controllers
-- HomeController
-- LoginController
My ultimate goal, is to have shared controllers that is being used as a fallback in the event that an area does not have the specified controller.
Scenario 1
User currently browse SomeArea1
and clicks on Login
. There is no LoginController
for SomeArea1
and he gets directed to SharedArea\Login
.
Scenario 2
User currently browse SomeArea2
and clicks on Login
. There is aLoginController
for SomeArea2
and he gets directed to SomeArea2\Login
.
How would one go about configuring your routes in the Startup.cs
file?
My current route setup in startup.cs
:
app.UseMvc(routes =>
{
routes.DefaultHandler = areaRouter;
routes.MapRoute("areaRoute", "{area:exists}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
areaRouter
is a custom implimentation for subdomain routing, you can view more here: subdomain routing to areas