我有重定向到另一個控制器和應用程序中的操作的問題。重定向到ASP中的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;
}
我model.Subject.Url例如在這種格式:Identity/User#/Details/b868b08c-b3ba-4f45-a7b6-deb02440d42f
它的面積/控制器/操作/ ID。 問題是,我RedirectResult重定向我:
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?}");
});
}
感謝您的幫助。
感謝您的回答。不幸的是,我沒有可能得到一個absoule網址。我總是得到這個相對的,這個URL可以指向其他的動作和控制器,所以我不能使用第二種解決方案。 – Ridikk12
請參閱我的更新,也不明白「用戶#」。這可能會造成問題。 – dotnetstep