wrong redirection using return RedirectToAction
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
);
}
If you want to change the path from
http://localhost/Project/index
to
http://localhost/webapp/Project/index
then put the prefix in your Route registration, like :
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"webapp/{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
- Is there a "/" in beginning of your routing?
- Did you make sure the virtual directory is set as Application in IIS?
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:
routes.MapRoute(
"Default", // Route name
"webapp/{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
精彩评论