C# 重定向到ASP核心中的URL
我在重定向到另一个控件和应用程序中的操作时遇到问题 我的重定向操作如下所示:C# 重定向到ASP核心中的URL,c#,asp.net,angularjs,asp.net-web-api,asp.net-core,C#,Asp.net,Angularjs,Asp.net Web Api,Asp.net Core,我在重定向到另一个控件和应用程序中的操作时遇到问题 我的重定向操作如下所示: public IActionResult Redirect(NotificationItemViewModel model) { NotificationItemToggleReadCommand command = new NotificationItemToggleReadCommand(); command.Id = new EntityId(model.Id);
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;
}
例如,我的model.Subject.Url的格式为:Identity/User#/Details/b868b08c-b3ba-4f45-a7b6-deb02440d42f
它是区域/控制器/动作/id。
问题是我的重定向结果将我重定向到:
notifications/Identity/User#/Details/b868b08c-b3ba-4f45-a7b6-deb02440d42f
并且该路由不存在(控制器/区域/控制器/操作/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?}");
});
}
谢谢你的帮助。如果我正确理解了你的问题,那是因为你在通知区域(其他区域)并试图离开该区域 为此,您可以执行以下任一操作
RedirectToActionResult redirectResult = new RedirectToActionResult("Details", "User", new { @area = "Identity", @Id = "b868b08c-b3ba-4f45-a7b6-deb02440d42f" });
return redirectResult;
~/Identity/User#/Details/b868b08c-b3ba-4f45-a7b6-deb02440d42f
谢谢你的回答。不幸的是,我没有可能得到一个绝对的网址。我总是得到这个相对的,这个url可以指向其他操作和控制器,所以我不能使用第二个解决方案。请查看我的更新,我也不理解“User#”。这可能会产生问题。对于重定向到外部URL,此答案可帮助您;对于重定向到外部URL,此答案可帮助您