Server.MapPath VS. @href ("~ / SomeFile.cshtml")

I followed the tutorials on MSDN and all of them (from what I saw) use @Href() for the URL. For instance.

<a href="@Href("~/")">Some link</a> , but I remember reading here a few months ago that it is safer to use Server.MapPath (), for example.

<a href="@Server.MapPath("~/")">Some link</a> , because it will convert it to the full path, which means that you cannot edit the base code to change where the form goes ( or something like that). It's true?

Should I use Href() or Server.MapPath() ? Which one is better, and why?

+4
source share
1 answer

More safely? I see no reason why, but I would not use it in Razor. That's why:

As far as I remember, the Href function from ASP.NET 1.0 times. When creating the WebForms (!) Code, you can simply paste ~ -URL <a href="~/" runat="server">Some link</a> .

However, if you are doing ASP.NET MVC (which I assume you have been doing since using Razor), you are better off using Url.Content() , which matches the value of Url.Action() -wise.

+5
source

All Articles