I have a link in my razor view like this:
<a href="Home/Login?ReturnUrl=Disputes/Index"> disputes</a>
Inside my login's action method, I am using this:
public ActionResult Login(string returnUrl) {
if (string.IsNullOrEmpty(returnUrl) && Request.UrlReferrer != null)
returnUrl = Server.UrlEncode(Request.UrlReferrer.PathAndQuery);
if (Url.IsLocalUrl(returnUrl) && !string.IsNullOrEmpty(returnUrl))
{
ViewBag.ReturnURL = returnUrl;
}
return View();
}
In view I am using this:
@Html.Hidden("returnUrl",@Request.QueryString)
Then in post action method:
public ActionResult LogOn(LogOnModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (membershipService.ValidateUser(model.UserName, model.Password, model.Type))
{
formsAuthenticationService.SignIn(model.UserName, model.RememberMe);
SetUserInfo(model.UserName);
string decodedUrl = "";
if (!string.IsNullOrEmpty(returnUrl))
decodedUrl = Server.UrlDecode(returnUrl);
if (Url.IsLocalUrl(decodedUrl))
return Redirect(decodedUrl);
else
return Redirect("Home", Index);
}
}
}
It is redirecting to:/Disputes/Index
but it should go to myApp/Disputes/Index
where the url with query string is like this. /myApp/Home/Login?ReturnUrl=/Disputes/Index
How can I solve this issue?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…