I have followed the tutorials over at MSDN and they all (from what I've seen) seem to use @Href() for URL's. E.g.
<a href="@Href("~/")">Some link</a> but I remember reading on here months ago that it is more secure to use Server.MapPath(), E.g.
<a href="@Server.MapPath("~/")">Some link</a> since it converts it to a full path, meaning that you cannot edit the underlying code to change where the form gets submitted to (or something like that). Is this true?
Should I use Href() or Server.MapPath()? Which one is better, and why?
More secure? I don't see a reason why - but I would use neither in Razor. Here's why:
As far as I remember, the Href function is from the ASP.NET 1.0 times. When doing WebForms (!) code you can just paste the ~-URL <a href="~/" runat="server">Some link</a>.
However, if you're doing ASP.NET MVC (which I assume you're doing since you're using Razor) you should rather use Url.Content() which fits with Url.Action() name-wise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With