Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The way your controller is set up is strange to me, but let's dive into it:</p> <pre><code> [HttpPost] public ActionResult Index(LogonModel model, string returnUrl) //changed { ReturnUrl = returnUrl; //changed if (ModelState.IsValid) { if (UserRepository.validLogin(model.Username, model.Password)) { UserLogRepository.createLogEntry("Log On", string.Format("{0} has logged on to the Staff Portal.", model.Username, "Entry/Exit"); //changed if (ReturnUrl.Length &gt; 1) //this should use IsLocalUrl { return Redirect(Request.QueryString["ReturnUrl"]); } else { return RedirectToAction("Dashboard", "Home"); } } else { ModelState.AddModelError("", Session["Error"].ToString()); } } // If we got this far, something failed, redisplay form return View(model); } </code></pre> <p>A few things: </p> <ol> <li><p>Your <code>returnUrl</code> needs to be checked to make sure it's a Local URL. There are a number of ways of doing this, and since you're using ASP.NET MVC 3, <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.islocalurl%28v=vs.98%29.aspx" rel="nofollow">it's built in</a>.</p></li> <li><p>Why are you pulling the ReturnUrl out of the querystring when (if you've set up your view correctly), it's already passed in?</p></li> </ol> <p>Do you have the following in your view?</p> <pre><code>&lt;%= Html.Hidden("returnUrl", Url.Encode(Url.Action("ActionToRedirectTo", "ControllerName", new { id = Model.Whatever}))) %&gt; </code></pre> <p>If so, when it posts, it will automatically get sent to the <code>Index</code> Action as the <code>returnUrl</code> parameter.</p> <p>I'm betting since it's not working, you aren't actually sending the ReturnUrl back correctly, check what I said about the view. Oh, and make sure you're URL encoding the <code>ReturnUrl</code>.</p> <p>Also, since it's a <code>HttpPost</code>, the querystring wouldn't have the return Url in it. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload