开发者

ASP.NET MVC Url display problem

I have recently been experimenting with the profile features of ASP.N开发者_运维知识库ET. 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜