2

I have an MVC3 Action that takes a parameter (a URL) that may have a query string in it. My action signature looks like this:

GetUrl(string url)

I expect to be able to send it urls, and it works every time unless there is a query string in the url. For example, if I navigate to:

MyController/GetUrl/www.google.com

the url parameter comes accross as "www.google.com" -Perfect. However, if I send MyController/GetUrl/www.google.com/?id=3 the url parameter comes accross as "www.google.com/" How do I get MVC3 to give me the whole URL in that parameter? -Including the query string?

0

2 Answers 2

1

It's simple enough to just URL.Encode the passed in URL on the page but you're opening your self to some possible security problems.

I would suggest you encrypt the url then encode it then pass that as your value, the protects you from having people just passing in anything into your app.

Sign up to request clarification or add additional context in comments.

Comments

1

That's because system considers id=3 as its own query string. When you construct the link in the view, you need to use @Url.Encode to convert raw url string to encoded string to be accepted as parameter of the controller.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.