I’m trying to learn ASP.NET Core. I’m still at the beginner level.
Sorry if my question is too simple.
I want to access the CoreBlogTeam/web/images/b1.jpg
image from /Views/Blog/BlogReadAll.cshtml
:
<img src="~/CoreBlogTema/web/images/b1.jpg"
<img src="/CoreBlogTema/web/images/b1.jpg"
Both file extensions img
work.
I researched the topics Physical Path, Virtual Path or Relative Virtual Path.
"../" //the parent directory
"/" //the site root directory
I understood information such as. But I still don’t understand the necessity of using “~/”. I’m still working on small projects on my own computer. I haven’t worked on the server side yet, maybe that’s why I’m having difficulty understanding it. If I use “/” instead of “~/”, I give the root directory and the file path works.
In the training videos I have watched, “~/” is used, but the reason for this is not explained.
Why do we have to use “~/”? I think it is a necessary condition on the server side, but I don’t fully understand it.
Again, sorry if it’s a simple question. I haven’t worked on the server side yet.
Thanks.