1

I have an url like this:

http://localhost:9562/Account/LogOn?ReturnUrl=%2fCabinet%2fCabinet

I need to parse it to this:

Cabinet/Cabinet

I've looked through this and this but i can't understand how to use it with my example.

Community
  • 1
  • 1
Arthur
  • 1,740
  • 3
  • 16
  • 36

2 Answers2

9

The easiest way would be to accept it as a parameter in your LogOn action:

public class AccountController : Controller
{
    public ActionResult LogOn(string ReturnUrl = "")
    {
    }
}

Note, providing a default value (i.e. = "") allows the action to execute even if the query parameter isn't present in the request.

Alternatively, you could access it through the Request property of your controller:

public class AccountController : Controller
{
    public ActionResult LogOn()
    {
        string request = this.Request.QueryString["ReturnUrl"];
    }
}
p.s.w.g
  • 146,324
  • 30
  • 291
  • 331
1

Try this:

 string r = Request.QueryString["ReturnUrl"].Substring(1);
 Response.Write(r);
Samiey Mehdi
  • 9,184
  • 18
  • 49
  • 63
  • I've tried it, but it doesn't work. But i tried it with Uri, not with string (Uri myUri = new Uri(returnUrl)) And It works. Thanks – Arthur Oct 29 '13 at 11:23