0

When the user try to visit the authenticated page, it is redirected to the LogOn page. Following is the LogOn action:

Controller Action

 [HttpPost]
  public ActionResult LogOn(LogOnModel model, string returnUrl)
  {
    //Authentication codes goes here .......
  }

LogOn View:

  @using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new {  @class = "jmenu" }))
   {
     // Form for login codes goes here......
  }

Problem: In LogOn View when I didn't put parameter in Html.BeginForm() it works fine as I want. The page is redirected to the page after login where the user is redirected to login for authentication. But if I pass parameter as above, after login it is redirected to the Home page. Here, it might be due to the returnUrl is not passed to the LogOn action. How can I passed returnUrl parameter in Html.BeginForm for LogOn action. OR, Is it possible without changing the view and modifying in the LogOn action so that I don't have to change for other view's code. Thanks for your time...

CodeManiac
  • 974
  • 8
  • 34
  • 56
  • try this http://stackoverflow.com/questions/9144930/asp-net-mvc-returnurl-variable-not-showing-up-with-method-formmethod-post-in-htm – Tushar Jul 29 '13 at 12:31

2 Answers2

0

You can use Request.UrlReferrer in your action to get the last request's URL.

Mohayemin
  • 3,841
  • 4
  • 25
  • 54
0

You'll want to define the return url as part of your form. One thing to note is that you cannot always rely on the url referrer. In some cases, it maybe null.

@{
    string url = "";
    if (ViewContext.HttpContext.Request.UrlReferrer != null)
    {
        url = ViewContext.HttpContext.Request.UrlReferrer.PathAndQuery;
    } 
}

@using (Html.BeginForm("Logon", "Account", new { model = this.Model, returnUrl = url }))
{
}
Dan Lister
  • 2,543
  • 1
  • 21
  • 36
  • http://stackoverflow.com/questions/9144930/asp-net-mvc-returnurl-variable-not-showing-up-with-method-formmethod-post-in-htm – Tushar Jul 29 '13 at 12:31