我遇到了在设置自定义表单身份验证票证后重定向到安全操作的问题。这是正在发生的事情:
任何人都可以放弃任何光线吗?
我的HomeController:
[Authorize]
public ActionResult Index()
{
return View();
}
我的AccountController:
[HttpGet]
[AllowAnonymous]
public ActionResult Login(string returnUrl)
{
ViewBag.ReturnUrl = returnUrl;
return View();
}
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginModel model, string returnUrl)
{
if (ModelState.IsValid)
{
bool bLogin = MyAuthentication.Login(model.UserName, model.Password);
if (bLogin)
{
Response.Cookies.Add(MyAuthentication.GetAuthenticationCookie(model.UserName.ToLower(), model.RememberMe));
RedirectToUrl(returnUrl);
}
else
ModelState.AddModelError("", "That is not a valid Username/Password combination");
}
return View(model);
}
private ActionResult RedirectToUrl(string returnUrl)
{
if (Url.IsLocalUrl(returnUrl))
return Redirect(returnUrl);
else
return RedirectToAction("Index", "Home");
}
以下是我创建自定义故障单的方法(仅添加userdata):
public static HttpCookie GetAuthenticationCookie(string UserName, bool persistLogin)
{
var userData = null; // Code removed for brevity
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
1,
UserName,
DateTime.Now,
DateTime.Now.AddMinutes(20),
persistLogin,
userData);
string encTicket = FormsAuthentication.Encrypt(authTicket);
return new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
}
答案 0 :(得分:3)
哎!
RedirectToUrl(returnUrl);
需要
return RedirectToUrl(returnUrl);