string path = context.Server.MapPath("~/Temp");
or
string path = context.Server.MapPath("/Temp");
are same ?
I know that '~' represents root but want to know diff bw ~/folder
and /folder
string path = context.Server.MapPath("~/Temp");
or
string path = context.Server.MapPath("/Temp");
are same ?
I know that '~' represents root but want to know diff bw ~/folder
and /folder
Absolute and relative path references in a server control have the following disadvantages:
Absolute paths are not portable between applications. If you move the application that the absolute path points to, the links will break.
Relative paths in the style of client elements can be difficult to maintain if you move resources or pages to different folders.
To overcome these disadvantages, ASP.NET includes the Web application root operator (~), which you can use when specifying a path in server controls. ASP.NET resolves the ~ operator to the root of the current application.
See http://msdn.microsoft.com/en-us/library/ms178116(v=vs.100).aspx
~/
resolves to the application root.
/
resolves to the site root.
When a server resource (like a control or view) is rendered, ~/
paths are resolved to site root paths based on the structure and context of the application (since ~/
is meaningless to a web browser).
To simplify, application root (~/
) is almost always the correct choice in ASP.Net applications (both web forms and MVC).