gpt4 book ai didi

asp.net-mvc-3 - MVC 3 - FormsAuthentication - 无法访问我的登录操作

转载 作者:行者123 更新时间:2023-12-01 09:36:56 24 4
gpt4 key购买 nike

我正在使用 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>

为了允许访问帐户 Controller ,我添加了以下内容:
<location path="~/Account">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>

这是我的问题 .我可以查看登录页面(帐户/索引),但我无法提交到帐户/登录。当我通过 Fiddler 观看正在发生的事情时,我会在发布到该页面时从服务器返回此文本:
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/Account/?ReturnUrl=%2faccount%2flogin">here</a>.</h2>
</body></html>

似乎当我将“~/Account”添加到完整的授权用户列表时,它并没有像在非 mvc 项目中那样真正工作。在 MVC 3 中有没有一种特殊的方法可以做到这一点?

最佳答案

Controller 的路径通常不被引用为相对路径。您应该只能说 location="Account",例如

<location path="Account">

无法确定这是您的问题,因为我现在无法对其进行测试,但可能是...

关于asp.net-mvc-3 - MVC 3 - FormsAuthentication - 无法访问我的登录操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5912585/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com