2011-03-29 84 views
1

我在我的MVC 3应用程序中使用了表单身份验证,并且遇到了我的返回URL问题。ASP.NET MVC 3 FormsAuthentication ReturnURL

当我标志着家庭控制器上的动作<Authorize>,它重定向到登录页面和作品,但返回URL然后/,所以当它重定向,它被重定向到当前URL Authorize的根源。

所以URL的是这样的:

http://localhost/ - 控制器=首页 - 行动=指数

http://localhost/Authentication/LogOn

我结束了这一点:http://localhost/Authentication/LogOn?ReturnURL=~%2F,我需要找回http://localhost/

帮助!! :)

+0

什么是你的http://本地主机/默认路由? – 2011-03-29 17:09:46

+0

@Nazar - 'routes.MapRoute(_ “Default”,_ “{controller}/{action}/{id}”,_ New with {.controller =“Home”,.action =“Index”, .id = UrlParameter.Optional} _ )' – Sam 2011-03-29 17:23:51

回答

2

试着改变你的帐号登录控制器动作是这样的:

[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); 
+0

FormsAuthentication处理我相信的路由。 – Sam 2011-03-29 17:24:41

+0

我想通了,我使用RedirectToAction,应该只使用重定向。谢谢!! – Sam 2011-03-29 17:39:56