0

I want to use a redirection to the requested URL a user wanted to access after the login but somehow the returnUrl is always null. (I did research on that topic for half an hour and didn't find a solution working for me.)

I debugged the Login view of my app and I'm trying to get the ReturnUrl with

new { ReturnUrl = Request.QueryString["ReturnUrl"] }

inside of my @using() tag. I saw that the QueryString is an empty collection and I even tried to use it without QueryString or just with ViewBag.ReturnUrl but neither the one nor the other worked for me.

The controller has the right parameters and it do redirect via RedirectToLocal(returnUrl) but that doesn't matter if the returnUrl is null.

3
  • What is the URL? If Request.QueryString["ReturnUrl"] is empty then it seems to follow that there is no ReturnUrl value on the query string. Commented May 9, 2016 at 11:38
  • Request.QueryString["ReturnUrl"] inside your view page will be empty. its available in controller Commented May 9, 2016 at 11:38
  • If you use the FormsAuthentication and all other pages are secured with Login, then the page requested will be automatically appended to ReturnUrl if browse for a page other than Login Commented May 9, 2016 at 11:42

2 Answers 2

0

In all your action methods,use this code

RedirectToAction("Login", "ControllerName", new { returnUrl = Request.Url.AbsolutePath });

In your Login action method use

public ActionResult Login(LoginViewModel model, string returnUrl){//code}
Sign up to request clarification or add additional context in comments.

Comments

0

Try this

 public ActionResult FirstAction()
    {
        return RedirectToAction("SecondAction",
            new { test = Request.Url.ToString() });
    }

    public ActionResult SecondAction()
    {
        return Redirect(Request.QueryString["test"]);
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.