How to Remove "http://localhost" from my URLs

L

Lee Roth

I am testing a web app that links to user defined URLs. I want the link
to be the exact text the user provided but I can't seem to get rid of
the "http://localhost" prefix in the link. Note that I am user defined
email addresses for "mailto:" links and the same problem occurs.

Is this something that will be removed when the site is published?

All help is appreciated,
Lee
 
D

Dmytro Lapshyn [MVP]

Does this prefix appear in the generated HTML code of the web page? Or is it
the browser who is too smart?
 
L

Lee Roth

It's the browser. The HTML in the code is basic. For example:

string userURL = userURLTextBox.Text; // say the user inputs
"www.google.com"
string htmlCode = "<a href = " + userURL + "> User Link </a>";

But instead of just google the link becomes
"http://localhost/www.google.com" which is a page it obviously can't
find.

So how do I use the code to make sure this doesn't happen to the end
users?

Thanks,
Lee
 
D

Dmytro Lapshyn [MVP]

Hey Lee,

You can automatically prefix any user input with http:// if the input does
not start with any protocol specification (bear in mind that these are not
only http:// or https://, can also be ftp:// or even telnet://)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top