Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could bring on the return URL all the way through the SignOn process, using the request query string.</p> <p>First, specify the page to return to whenever you render your SignOn partial:</p> <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %&gt; &lt;%@ Import Namespace="Microsoft.Web.Mvc"%&gt; &lt;!-- Your Example/Page1 page --&gt; &lt;% if (!User.IsAuthenticated) %&gt; &lt;%= Html.RenderAction("SignOn", "Account", new { returnUrl = Request.Url.PathAndQuery }); %&gt; </code></pre> <p>Use RenderAction if the current context is not the Account Controller. The feature is currently not in the MVC release, so you need to include the <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24471" rel="nofollow noreferrer">ASP.NET MVC's Future library</a> in your solution.</p> <p>Next, the SignOn controller:</p> <pre><code>public ActionResult SignOn(string returnUrl) { if (User.Identity.IsAuthenticated) { User user = userRepository.GetItem(u =&gt; u.aspnet_UserName == User.Identity.Name); return !string.IsNullOrEmpty(returnUrl) ? Redirect(returnUrl) : (ActionResult) RedirectToAction("Index", "Home"); } return PartialView(); } </code></pre> <p>SignOn form:</p> <pre><code> &lt;% using (Html.BeginForm("SignOn", "Account", new { returnUrl = Request.QueryString["returnUrl"] },FormMethod.Post,new {@class="my_signOn_class"})) { %&gt; &lt;!-- Form --&gt; &lt;% } %&gt; </code></pre> <p>Finally, in your SignOn controller that processes the Form POST, you can return the user to the 'returnURL' using the following code:</p> <pre><code>[AcceptVerbs(HttpVerbs.Post)] public ActionResult SignOn(FormCollection formCollection, string returnUrl) { if (BusinessRuleViolated(formCollection)) { if(!string.IsNullOrEmpty(returnUrl)) { return Redirect(returnUrl); } return RedirectToAction("Index", "Home"); } // SignIn(...) } </code></pre>
 

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