C# 为什么RedirectToAction会重定向到<;参数>;。通用域名格式
我们有一个mvc4站点,其中HomeController.Index()包含以下代码C# 为什么RedirectToAction会重定向到<;参数>;。通用域名格式,c#,asp.net,.net,asp.net-mvc,asp.net-mvc-4,C#,Asp.net,.net,Asp.net Mvc,Asp.net Mvc 4,我们有一个mvc4站点,其中HomeController.Index()包含以下代码 RedirectionToAction("Page", new { id = "Home" } ); 其中操作页面定义为 public ActionResult Page(string id) ..... 调试时,它以localhost:xxxxx启动,然后重定向到www.home.com 在设置断点时,它甚至不会命中方法页面(字符串id) 有什么线索可以找到吗?看起来您可能有一些路由问题。Rou
RedirectionToAction("Page", new { id = "Home" } );
其中操作页面定义为
public ActionResult Page(string id)
.....
调试时,它以localhost:xxxxx
启动,然后重定向到www.home.com
在设置断点时,它甚至不会命中方法页面(字符串id)
有什么线索可以找到吗?看起来您可能有一些路由问题。RouteConfig.cs文件位于MVC4项目的App_Start文件夹中 还有一件事,如果页面操作位于与HomeController不同的控制器中,则需要如下代码:
public ActionResult Index()
{
return RedirectToAction("OtherController", "Page", new { id = "Home" });
}
我创建了一个带有重定向的基本MVC4项目,它适合我。用户在以下URL处结束:[http://localhost:47272/Home/Page/Home] 这是我的HomeController.cs
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return RedirectToAction("Page", new { id = "Home" });
}
public ActionResult Page(string id)
{
return View();
}
}
这是我的路线图
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
在解决方案范围内搜索
home.com
您可能在某个地方定义了它,它导致了重定向(可能是您的默认错误页?@Kenneth已经找到了,但没有找到它您是否通过JavaScript或301/302获得重定向?Routeconfig.cs文件中有什么内容?@Kenneth我如何找到它?