小编Rid*_*k12的帖子

重定向到ASP CORE中的URL

我有重定向到另一个控制器和应用程序中的操作的问题.

我的重定向操作看起来像:

    public IActionResult Redirect(NotificationItemViewModel model)
    {
        NotificationItemToggleReadCommand command = new NotificationItemToggleReadCommand();
        command.Id = new EntityId(model.Id);
        command.MarkAsRead = true;


        var result = CommandProcessor.Run(command);
        RedirectResult redirectResult = new RedirectResult(model.Subject.Url,true);
        return redirectResult;
    }
Run Code Online (Sandbox Code Playgroud)

我的model.Subject.Url例如是这种格式: Identity/User#/Details/b868b08c-b3ba-4f45-a7b6-deb02440d42f

它是区域/控制器/动作/ id.问题是我的RedirectResult将我重定向到:

notifications/Identity/User#/Details/b868b08c-b3ba-4f45-a7b6-deb02440d42f 
Run Code Online (Sandbox Code Playgroud)

并且该路由不存在(controller/area/controller/action/id)如何强制此重定向切断第一个控制器名称?

我的路线:

    app.UseMvc(routes =>
        {
            routes.MapRoute("areaRoute", "{area:exists}/{controller}/{action=Index}/{id?}");

            routes.MapRoute(
                name: "controllerActionRoute",
                template: "{controller}/{action}",
                defaults: new { controller = "Home", action = "Index" },
                constraints: null,
                dataTokens: new { NameSpace = "default" });

            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }
Run Code Online (Sandbox Code Playgroud)

感谢帮助.

c# asp.net asp.net-web-api angularjs asp.net-core

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

angularjs ×1

asp.net ×1

asp.net-core ×1

asp.net-web-api ×1

c# ×1