开发者

What is the difference between Href and Url.Content?

开发者 https://www.devze.com 2023-02-08 01:22 出处:网络
Both Href and Url.Content can be used to resolve a virtual path, which is relative to the virtual root path ~, of files or folders.

Both Href and Url.Content can be used to resolve a virtual path, which is relative to the virtual root path ~, of files or folders.

What is the difference between Href and Url.Content ?开发者_JAVA技巧


url.content does alot more than just creating an normal href, it takes into context the application's sub/virtual directory, whereas href it's a straight pointer.

for best practice use url.content, this way you know that if your site moves into a sub/virtual directory, your link will still work.


They're quite similar, though Href comes from the ASP.NET WebPages stack. In an MVC context you should use Url.Content.


Href is part of System.Web.WebPages and Url.Content is part of System.Mvc. I think that if you have an MVC app, you'll get both, but some other usages (like webforms) will only have Href available to them.

0

精彩评论

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