使用 return RedirectToAction 进行错误重定向
我需要将用户从一个控制器重定向到另一控制器。
我正在使用
return RedirectToAction("Index", "Project");
它工作得很好,除非我发布了我的网站。我的网站正在 IIS 目录中运行,但网址看起来像这样
http://localhost/Project/index
,但它应该是正确的
http://localhost/webapp/Project/index
编辑
你的意思 开头是否有一个“/”你的路由?
?
是的,目录设置为 IIS 应用程序。
没有什么特别的,但它是:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
I need to redirect the user from one controller to other controller.
I'm using
return RedirectToAction("Index", "Project");
It worked great unless I published my web.My web is running in a IIS directory,but the url looks like this
http://localhost/Project/index
but it should be right
http://localhost/webapp/Project/index
EDIT
What do you mean with Is there a "/" in beginning of your routing?
?
Yes, the directory is set to an IIS application.
There's nothing special but here it is:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想将路径从 更改为
,
请将前缀放入您的路由注册中,例如:
If you want to change the path from
to
then put the prefix in your Route registration, like :
将您的路由规则添加到问题中以帮助您提供更多帮助(然后请在您这样做时对答案进行评论,让我知道您这样做了,谢谢)。t
Add your routing rules to the question to help you more (and then please comment on the answer when you do to let me know that you did, thanks).t
改变你的路线:
Change your route: