Question

I have recently been experimenting with the profile features of ASP.NET. I am having trouble getting a "website" property to display correctly. For example, if the website I enter is:

facebook.com/contactalig
and I render it using
<a href="<%: Profile.Website %>"><%: Profile.Website %></a>
it gets rendered on screen as
http://localhost:51225/users/facebook.com/contactalig
Initially, I thought I might just prepend "http://" if it didn't contain one, but I feel there should be a cleaner solution.

Thanks in advance.

Was it helpful?

Solution

Without the protocol etc it isn't an absolute uri, so the browser (correctly) treats it as relative to the current URL.

So yes: check for a protocol. Perhaps just StartsWith is enough here, else a regex or maybe Uri.TryCreate (or whatever it is) specifying absolute-only.

Personally I would do this check at the point of data-entry, not at display.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top