Asp.net mvc 登录后不重定向到下一页

Asp.net mvc 登录后不重定向到下一页,asp.net-mvc,forms,model-view-controller,forms-authentication,Asp.net Mvc,Forms,Model View Controller,Forms Authentication,身份验证后,我将上述代码片段保存在web.config文件中,问题开始出现。我输入了正确的凭据,但在成功登录后,我仍然没有重定向到下一页 我的新url被附加了一些查询字符串值 这是我的登录url: http://localhost:49841/LMIT/Login 提交具有正确凭据的登录表单后,它不会重定向到下一页,而是与http://localhost:49841/LMIT/Login?ReturnUrl=%2fLMIT%2fIndex在url中确定,请尝试以下代码: [AllowAnonym

身份验证后,我将上述代码片段保存在web.config文件中,问题开始出现。我输入了正确的凭据,但在成功登录后,我仍然没有重定向到下一页 我的新url被附加了一些查询字符串值 这是我的登录url:

http://localhost:49841/LMIT/Login

提交具有正确凭据的登录表单后,它不会重定向到下一页,而是与
http://localhost:49841/LMIT/Login?ReturnUrl=%2fLMIT%2fIndex
在url中

确定,请尝试以下代码:

[AllowAnonymous]
public ActionResult Login(Users user)
{
    Users DbData = (from s in db.Users where s.UserName == user.UserName select s).First();
    if (DbData != null)
    {
        if (user.UserName == DbData.UserName && user.Password == DbData.Password)
        {
            FormsAuthentication.SetAuthCookie(user.Id.ToString(), true);
            return Json(new { ok = true, newurl = Url.Action("/Index") });
        }
    } 
    return View();
} 

您需要为您的登录操作方法[AllowAnonymous]公共操作结果登录(Users user){Users DbData=(从db.Users中的s开始,其中s.UserName==user.UserName选择s.First();if(DbData!=null){if(user.UserName==DbData.UserName&&user.Password==DbData.Password){return Json(new{ok=true,newurl=Url.Action(“/Index”)};}}else{}return View();}因为我使用的是ajax和json,所以我使用了returnm jsonIt,最好用添加的代码更新问题。这样更容易理解。此外,您可以返回json,这不是问题,但您还需要设置一个cookie,告诉ASP.NET用户已通过身份验证。如果我不使用Authorize,如果我保留了授权然后只有我出错