我使用MVC 3和FormsAuthentication:MVC 3 - FormsAuthentication - 不能给访问我的登录操作
<authentication mode="Forms">
<forms loginUrl="~/Account/" timeout="2880" />
</authentication>
我的帐户/索引页面显示登录页面,然后使用jQuery,它做了发布到帐户/登录以验证用户。下面是处理它我的AccountController行动:
[HttpPost]
[Authorize(Users = "*")]
public ActionResult Login(string userName, string password) {
...
}
而且Jquery的这帖吧:
$.post("/account/login", {
"userName": $("#userName").val(),
"password": $("#password").val()
}, function (data) {
...});
以上所有的作品,但现在我想限制该网站的一般访问,所以我加了这对我的根web.config:
<authorization>
<deny users="?" />
</authorization>
,企图以允许访问账户控制器,我添加了这个:
<location path="~/Account">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
这是我的问题。我可以查看登录页面(帐户/索引),但我无法提交到帐户/登录。当我看这是怎么回事通过提琴手,我得到张贴到该网页时,该文本从服务器返回:
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/Account/?ReturnUrl=%2faccount%2flogin">here</a>.</h2>
</body></html>
看来,当我添加“〜/帐户”充分授权用户列表它不是”在非mvc项目中的工作方式非常类似。有没有一种特殊的方式在MVC 3中做到这一点?
谢谢,这是问题所在。总是那么简单,我忽略了...... :) – bugfixr 2011-05-06 14:32:54