1

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://example.com to http:/example.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(":/", "://");
}
Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54
ahmadali shafiee
  • 4,350
  • 12
  • 56
  • 91

2 Answers2

2

use regex:

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

if you need to revert:

string src = @"http:/example.com";
string result = Regex.Replace(src, @"(?<=https?:)/(?=[^/])", @"//");
Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54
burning_LEGION
  • 13,246
  • 8
  • 40
  • 52
2

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/example.com/

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

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

Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54
mafue
  • 1,858
  • 1
  • 21
  • 27