开发者

Can you specify the differences ./,../,~/ in ASP.NET?

开发者 https://www.devze.com 2023-01-25 12:45 出处:网络
What are the differences between ./, ../, and ~/ f开发者_运维问答or specifying an image in my web application?

What are the differences between ./, ../, and ~/ f开发者_运维问答or specifying an image in my web application?

Like current directory, root, parent directory, etc.


"./"  //the current directory
"../" //the parent directory
"/"   //the site root directory
"~/"  //virtual root Web path


ASP.NET Web Project Paths is a very good article in MSDN regarding paths in ASP.NET with good examples.


Web Pathing:
./ means this folder, equivalent to nothing on the front
ex: ./image.jpg and image.jpg are the same thing
/ the web application root folder
ex: /Test/image.jpg, go to the application root, find folder Test, find image.jpg
../ means up one folder then go to the folder after the slash...
ex: ../Test/image.jpg, go up one folder from the current folder your in, go into folder Test, and find image.jpg.


Physical Pathing:
~/ means the application physical root folder. This will not work if you are using it directly in the webpage (ex: <img src="~/images/image.jpg" />). You can use ResolveUrl to get the web path to a file. I have used this for referencing JavaScript libraries in a master page. I've also seen it used in some custom uploaders.

0

精彩评论

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