How to route subdomain in .NET CORE MVC?

asp.net
voted: 1
vote
.net asp.net asp.mvc subdomain

Catch route from subdomain in controller using AspNetCoreSubdomain library.

// Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    var hostnames = new[] { "localhost:54575" };
    
    app.UseMvc(routes =>
            {
                routes.MapSubdomainRoute(
                    hostnames: hostnames,
                    subdomain:"{area}",
                    name: "SubdomainDefault",
                    template: "{controller=Home}/{action=Index}");
    });
}
//cshtml file
@Html.ActionLink("Hyperlink example", "Action1", "Home", new { area = "Area1" })
//controller under Area1
public IActionResult Action1()
{
    //code
}
working url: https://github.com/mariuszkerl/AspNetCoreSubdomain
version: .netcore
Leave a Comment:
Characters left:
No comments yet.