I created Admin Area inside my ASP.NET Core application and updated my routes like that:
app.UseMvc(routes =>
{
routes.MapRoute(name: \"areaRoute\",
Michael Graf has a blog post about it.
Basicly you need a custom router:
public class AreaRouter : MvcRouteHandler, IRouter
{
public new async Task RouteAsync(RouteContext context)
{
string url = context.HttpContext.Request.Headers["HOST"];
var splittedUrl = url.Split('.');
if (splittedUrl.Length > 0 && splittedUrl[0] == "admin")
{
context.RouteData.Values.Add("area", "Admin");
}
await base.RouteAsync(context);
}
}
And then register it.
app.UseMvc(routes =>
{
routes.DefaultHandler = new AreaRouter();
routes.MapRoute(name: "areaRoute",
template: "{controller=Home}/{action=Index}");
});
On the other hand we have the IIS Rewrite module, or even a Middleware