.NET Core MultiTenancy causing Area routing in ajax to not work

Deadly 提交于 2020-01-25 08:22:11

问题


I am using the Finbuckle Multitenant Library and I have encountered an issue with routing to Areas in my Views when I try to do ajax calls.

private static void ConfigRoutes(Microsoft.AspNetCore.Routing.IRouteBuilder routes)
{
    routes.MapRoute("Login", "Login", new { controller = "Account", action = "Login", area="Identity"});
    routes.MapRoute("Default", "{__tenant__=}/{controller=Home}/{action=Index}/{id?}");
    routes.MapRoute("AreaGeneric", "{area:exists}/{controller=Home}/{action=Index}/{id?}");
    routes.MapRoute("Area", "{__tenant__=}/{area:exists}/{controller=Home}/{action=Index}/{id?}");
}

These are the routeMaps that a defined in my Startup.cs

<script>
    $(document).ready(function(e){
        $.ajax({
            url: "@Url.Action("Preview", "Account",new { area="Identity"})",
            success: function (result) {
                $("#user-container").empty();
                var url = "@Url.Action("Index","Manage",new { area="Identity"})";
                $("#user-container").append($('<a href="' + url+'"><h5>Welcome, ' + result.UserDetails.FirstName + " " + result.UserDetails.LastName +'</h5></a>'));
            }
        });
    });
</script>

This is the ajax script that is having the issue. The url always reads as

https://localhost:44311/TenantOne/Account/Preview?area=Identity

instead of

https://localhost:44311/TenantOne/Identity/Account/Preview

What can I do to solve this? I'm not sure that I missed anything in my routing.

来源:https://stackoverflow.com/questions/59153320/net-core-multitenancy-causing-area-routing-in-ajax-to-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!