[英]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.