RedirectToAction(“索引”,“用户”)被自定义索引捕获,但RedirectPermanent(“/user/ RouteHandler /”)没有问题
在一个动作中,代码就像这样
public ActionResult AddSimpleDescription(TSimpleDescription entity2, string url, string which)
{
//my colds
return RedirectToAction("Index", "User");
}在全局文件中,我注册一个自定义RouteHandler,如下所示
public static void RegisterHandler(RouteCollection routes)
{
routes.Add("upload_file",
new Route("upfile/bkup/nsksjskjs/", new HHT.Utility.Components.CompressRoutHandler()));
}当我的代码在动作AddSimpleDescription中运行完成时,然后执行RedirectToAction(“索引”,“用户”),页面转到url "http://localhost:59000/upfile/bkup/nsksjskjs?action=Index&controller=User“为什么?我该如何解决这个问题?
索引动作代码
公共ActionResult索引(字符串参数,字符串id) { getUserName();
//ViewBag.RCount = remindbll.GetCount(int.Parse(User.Identity.Name));
return View();
}
catch (Exception ex)
{
return Render(3, ex.Message);
}
}发布于 2012-06-05 11:57:08
好吧,这是因为你使用的是自定义路由,我不知道"upload_file“是否是你唯一的路由……但在使用自定义路径时,必须指定要使用的路径,否则将使用默认路径
你有下面的注册路径...
public static void RegisterHandler(RouteCollection routes)
{
routes.Add("default_route", new Route("{controller}/{action}/{id}", new {controller = "controller", action = "action", id = UrlParameter.optional})
routes.Add("upload_file",
new Route("upfile/bkup/nsksjskjs/", new HHT.Utility.Components.CompressRoutHandler()));
}因此您必须指出应该使用哪条路由
return RedirectToRoute("default_route");https://stackoverflow.com/questions/10879401
复制相似问题