我有一个简单的登录表单,我希望发布到ASP.Net MVC。我发现如果操作设置为/登录,它就可以工作。但是,如果我写出诸如“/ Login/Index”之类的操作名称,那么它将失败。服务器将302返回到登录页面,并且从不调用Index()的POST版本。为什么是这样?为什么此表单的请求无效?
这里的HTML:
<form action="/Login/Index/" method="post">
<label for="username">Username</label>
<input type="text" id="username" name="username" maxlength="60" />
<label for="password">Password</label>
<input type="password" id="password" name="password" maxlength="20" />
<input type="submit" value="Login" />
</form>
这里的控制器:
public class LoginController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string username, string password)
{
return null;
}
}
这里是在Global.asax中定义的唯一途径
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Movie", action = "Index", id = UrlParameter.Optional }
);
解决: 在我的网站.Config我有loginUrl =“〜/ Login”和i t需要是“〜/登录/索引”,否则拒绝访问该URL并将其重定向回登录页面。
您是否可以在不重建的情况下对您的视图进行更改? – 2011-12-29 17:42:40
监视像Firebug这样的活动客户端。如果'method'是'post',它应该执行一个POST,但它可能会立即被重定向到其他的东西。那里可能有线索。 – David 2011-12-29 17:43:16
对不起其实我看到我得到一个POST,但服务器用302回应登录。为什么POST版本的Index不会被调用? – 2011-12-29 17:53:27