Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么RedirectToAction会重定向到<;参数>;。通用域名格式_C#_Asp.net_.net_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

C# 为什么RedirectToAction会重定向到<;参数>;。通用域名格式

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

我们有一个mvc4站点,其中HomeController.Index()包含以下代码

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我如何找到它?