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.

2 Answers 2

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"];
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

 string r = Request.QueryString["ReturnUrl"].Substring(1);
 Response.Write(r);

1 Comment

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

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.