[英]ASP.NET MVC 3 FormsAuthentication ReturnURL
我在我的 MVC 3 应用程序中使用表单身份验证并且我的返回 URL 有问题。
当我在 Home 控制器上标记一个操作<Authorize>
时,它会重定向到登录页面并工作,但返回 URL 是/
,因此当它重定向时,它会重定向到当前 URL Authorize
的根。
所以网址是这样的:
http://localhost/ - 控制器 = 主页 - 操作 = 索引
http://localhost/Authentication/LogOn
我最终得到这个: http://localhost/Authentication/LogOn?ReturnURL=~%2F ,我需要回到http://localhost/
帮助!! :)
尝试将您的帐户控制器登录操作更改为如下所示:
[HttpPost]
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (MembershipService.ValidateUser(model.UserName, model.Password))
{
FormsService.SignIn(model.UserName, model.RememberMe);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", "The user name or password provided is incorrect.");
}
}
// If we got this far, something failed, redisplay form
return View(model);
http://localhost/Authentication/LogOn?ReturnURL=~%2F ,表示home url重复
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.