Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass URL as get parameter?

Tags:

asp.net-mvc

I'm trying to pass u url as parameter to a get method. I defined a route that accepts a {*url} parameter so I can send "/" characters without it separating my parameter. As soon as there is a ":" in the url (like in http: or localhost:3857 for example), the method never gets hit.

The Html.ActionLink method escapes it's parameter itself, but it doesn't seem to escape the ':'. I cannot escape it manually because then the escape characters get escaped by the very same Html.Actionlink method.

any ideas?

like image 769
Boris Callens Avatar asked Dec 09 '08 13:12

Boris Callens


People also ask

Can I pass a URL as parameter?

A URL parameter is a way to pass data in a link to a web page. You can use URL parameters to track different metrics in services like Google Analytics or Google Ads, and in Unbounce to pre-fill your form.

How do you pass a URL as parameter in HTTP request?

Any word after the question mark (?) in a URL is considered to be a parameter which can hold values. The value for the corresponding parameter is given after the symbol "equals" (=). Multiple parameters can be passed through the URL by separating them with multiple "&".

Can we pass parameters in GET request?

In a GET request, you pass parameters as part of the query string.

How do you give a URL parameter?

To identify a URL parameter, refer to the portion of the URL that comes after a question mark (?). URL parameters are made of a key and a value, separated by an equal sign (=). Multiple parameters are each then separated by an ampersand (&).


2 Answers

Use EncodeUrl before you pass it, and then decode it on the other side.

like image 198
Kieveli Avatar answered Oct 23 '22 08:10

Kieveli


I ran into the same problem. I ended up removing the Html.ActionLink and replaced it with:

<a href="[email protected]">@item.Title</a>

@item.ID is a url returned from the netflix api, example http://api.netflix.com/catalog/titles/series/70021357/seasons/70021357. Now my url looks like this - /Home/Movies?id=http://api.netflix.com/catalog/titles/series/70021357/seasons/70021357, and I just used Request.QueryString to get the value in the controller:

Request.QueryString.Get("id")

Probably not ideal but it works for now.

like image 34
tessa Avatar answered Oct 23 '22 06:10

tessa