[英]AJax call issue with Form authentication in MVC4
I am using cookie based form authentication in my application and login in my application through ajax .when i apply Authorization tag in my web.config.my ajax function stop calling login action method in controller. 我在应用程序中使用基于cookie的表单身份验证,并通过ajax登录应用程序。当我在web.config.my中应用Authorization标签时,我的ajax函数停止在控制器中调用登录操作方法。 my code is here.any suggestion please... 我的代码在这里。任何建议请...
<authorization>
<deny users="?"/>
</authorization>
Controller ActionMethod 控制器动作方法
[HttpPost]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Login(string userName, string Password)
{}
AJAX Method AJAX方法
$.ajax({
type: "POST",
url: '@Url.Action("Login", "Secur")',
data: "{userName:'" + UName + "',Password:'" + UPwd + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (msg) {
if (msg == "Successed") {
window.location.href = "Home/Dashboard";}
},
error: function (e) {`enter code here
return false;
}
})
I think your problem is this. 我想你的问题是这个。 In the config you have: 在配置中,您可以:
<deny users="?"/>
Which means deny anonymous users. 这意味着拒绝匿名用户。 But the controller method has this attribute: 但是controller方法具有以下属性:
[AllowAnonymous]
That seems odd. 好像很奇怪 Either that method is callable by anyone, or it's not; 该方法是任何人都可以调用的,或者不是。 it can't be both. 不能两者兼有。
EDIT: 编辑:
To make things easier, removing the config setting 为了简化操作,删除配置设置
<deny users="?"/>
means anyone can access the site, since you are not using the [Authorise]
attribute, but are using [AllowAnonymous]
. 表示任何人都可以访问该站点,因为您没有使用[Authorise]
属性,而是使用[AllowAnonymous]
。 If you do have 如果你有
<deny users="?"/>
then you must remove [AllowAnonymous]
and add the [Authorise]
attribute. 那么您必须删除[AllowAnonymous]
并添加[Authorise]
属性。 Let us know if it's still not working. 让我们知道它是否仍然无法正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.