Search code examples
c#asp.net-mvcc#-4.0asp.net-mvc-routingasp.net-mvc-4

Input URL like http://example.com changes to http:/example.com in action input


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(":/", "://");
}

Solution

  • 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