I asked a question to get url as action input here. Now I have a new problem. The passed url to action changes from http://google.com to http:/google.com.

I want to know why and how can I resolve the problem.

P.S: I added this code to resolve but I think there may be another problems in future! the code is:

if ((url.Contains(":/")) && !(url.Contains("://")))
{
    url = url.Replace(":/", "://");
}
share|improve this question
2  
on an unrelated note, it looks like your code is replacing all depressed/undecided faces with slanty scared-looking faces. – Phillip Schmidt Aug 7 '12 at 19:54
feedback

2 Answers

up vote 2 down vote accepted

The browser (or server) is replacing a double slash (illegal) with a single one.
Try it,

http://stackoverflow.com/questions/11853025//input-url-like-http-site-com-changes-to-http-site-com-in-action-input

(in Chrome) goes to:

http://stackoverflow.com/questions/11853025/input-url-like-http-site-com-changes-to-http-site-com-in-action-input

If I were you, I would remove the http:// from your path and add it later.

http://localhost:1619/Utility/PR/google.com/

Then, url = "http://" + url;

If you might get secure urls, add that to the route /http/google.com or /https/google.com

share|improve this answer
thanks for the reason! but I will use my own solution! – ahmadali shafiee Aug 7 '12 at 20:10
feedback

use regex:

string src = @"http://google.com";
string result = Regex.Replace(src, @"(?<=https?:/)/", "");

if you need to revert:

string src = @"http:/google.com";
string result = Regex.Replace(src, @"(?<=https?:)/(?=[^/])", @"//");
share|improve this answer
is it better than the code I wrote? – ahmadali shafiee Aug 7 '12 at 19:59
and do you know why it happens? – ahmadali shafiee Aug 7 '12 at 20:00
yes, my code replace href slashes in any string correctly, your code wrong if string would be like http://google.com http:/google.com – burning_LEGION Aug 7 '12 at 20:02
Thanks. I'll use your way but I'd rather to know why. sorry to not set your answer as accepted! – ahmadali shafiee Aug 7 '12 at 20:14
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.