I have a simple login screen in .Net MVC. I use Redirect() method to redirect to the given url after succesful login, but Redirect(url) does not get anywhere, the page remains in the login screen.
Below link gets returnurl fine:
@Html.ActionLink("Buy","Login","Account",new { returnUrl = Request.RawUrl })
Then in the login screen, returnUrl shows this url:
http://localhost:1820/Account/Login?returnUrl=%2FBasket%2FGoToShopCart
Redirect(url) which is not redirecting:
[HttpPost]
public ActionResult Login(Login l, string returnurl)
{
RegisteredCustomer rc = new RegisteredCustomer();
string url = "";
Repository r = new Repository();
var obj = r.GetUser(l);
if (obj != null)
{
Session["UserID"] = obj.RegisterID.ToString();
url = returnurl;
}
else
url ="/Account/Login";
return Redirect(url);
}`
And I pass url to HttpPost method here in login View:
`@using (Html.BeginForm("Login", "Account", new { returnUrl = Request.QueryString["ReturnUrl"] }, FormMethod.Post))
{
@Html.Hidden("returnUrl", ViewContext.HttpContext.Request.Url.PathAndQuery)
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
...
<input type="submit" value="Enter" />
}`
Also it is not redirecting this url neither :
http://localhost:1820/Account/Login
I have checked these answers but couldn't help me:
Redirect to returnURL not working Redirect request to 'ReturnUrl' displays Login Page
You can use return RedirectToAction("Login","Account");