Asp.net mvc 4 将Http 302对象移动到的ASP.NET MVC路由配置
我想我的MVC路由可能有点问题。注意,我将ASP.NETMVC4与Razor视图一起使用 我的路线登记如下:Asp.net mvc 4 将Http 302对象移动到的ASP.NET MVC路由配置,asp.net-mvc-4,asp.net-mvc-routing,http-status-code-302,Asp.net Mvc 4,Asp.net Mvc Routing,Http Status Code 302,我想我的MVC路由可能有点问题。注意,我将ASP.NETMVC4与Razor视图一起使用 我的路线登记如下: routes.MapRoute( "Person", "Person/Show/{uniqueId}", new { controller = "Person", action = "Show", uniqueId = "" } ); routes.MapRoute( name: "Defa
routes.MapRoute(
"Person",
"Person/Show/{uniqueId}",
new { controller = "Person", action = "Show", uniqueId = "" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional}
);
[HandleError]
public class PersonController{
public ActionResult Show(string uniqueId)
{
//get data from database
var personData = GetPersonDataFromDatabase(uniqueId);
return View("PersonView", new PersonViewModel(personData));
}
}
@Html.Action("SomeListPartial", "Other")
我的PersonController实现如下:
routes.MapRoute(
"Person",
"Person/Show/{uniqueId}",
new { controller = "Person", action = "Show", uniqueId = "" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional}
);
[HandleError]
public class PersonController{
public ActionResult Show(string uniqueId)
{
//get data from database
var personData = GetPersonDataFromDatabase(uniqueId);
return View("PersonView", new PersonViewModel(personData));
}
}
@Html.Action("SomeListPartial", "Other")
这应该显示PersonView.cshtml,它的布局为_LayoutContent.cshtml,而布局为_layout.cshtml
不幸的是,我无法看到该页面。。。。除非我已经登录。我不知道为什么会有不同
当我在未登录的情况下尝试加载页面时,我将被发送到此页面:
http://mymachine:8083/?ReturnUrl=%2fPerson%2fShow%2fvXDwucay
当我使用Fiddler查看正在发生的事情时,我可以看到以下情况:
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/?ReturnUrl=%2fPerson%2fShow%2fvXDwucay">here</a>.</h2>
</body></html>
对象已移动
对象移动到。
有人能给我指出导致这个问题的正确方向吗?我觉得很奇怪,登录会导致路由正常工作。我肯定我一定是做错了什么简单的事情……或者我没有找到解决问题的正确方法。我终于找到了解决问题的方法。我能够追踪我的问题到一个特定的修订版…在大量关注代码之后,我终于能够对解决方案有一个顿悟 我在这里发布解决方案,以防将来有人遇到这个问题 在“PersonView”中,我显示了一个局部视图,该视图返回一些数据,如下所示:
routes.MapRoute(
"Person",
"Person/Show/{uniqueId}",
new { controller = "Person", action = "Show", uniqueId = "" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional}
);
[HandleError]
public class PersonController{
public ActionResult Show(string uniqueId)
{
//get data from database
var personData = GetPersonDataFromDatabase(uniqueId);
return View("PersonView", new PersonViewModel(personData));
}
}
@Html.Action("SomeListPartial", "Other")
当我读到这篇文章时,我误以为是@Html.ActionLink方法提供了一个指向页面的超链接,@Html.Action方法“使用指定的控制器名称调用指定的子操作方法,并以Html字符串的形式返回结果。”…这意味着它执行操作并返回结果html以显示在屏幕上
当我查看正在调用的操作时,发现我(正确地)在其上放置了一个[Authorized]属性…这就是为什么它在未登录时失败的原因
现在我不完全确定为什么错误没有更明显…但我认为我的网站中一定有某种东西进行了重定向,这就是为什么我会自动被带到?ReturnUrl=%2fPerson%2fShow%2ffxdwucay