0

This is similar to relative path to CSS file [closed]. but it's about Java web application and what I am talking about is .NET. They're the same?

I am having an issue with ASP.NET core. In the Index.cshtml, there are some codes, which include CSS static files:

...
<link href="~/css/features.css" rel="stylesheet">
<link href="~/css/carousel.css" rel="stylesheet">
...

The problem is that I am getting 404 error on the web page. Seems like the path is not correct in the code. see the attached screenshots: enter image description here

How can I resolve this? Why it causes an issue?

FYI: I am attaching the screenshots of the folder structure and code snippets. enter image description here

enter image description here

JShobbyist
  • 532
  • 3
  • 9
  • 23
  • @user09938 thanks for your suggestion, but the link to "**relative path to CSS file**" is about `JAVA`. The question I am asking is about `asp.net` core. – JShobbyist Dec 17 '22 at 19:07
  • Your first image is very unclear. What URL is it trying to load? – Avrohom Yisroel Dec 17 '22 at 19:58
  • 1
    Your certainly isn't a duplicate of that Java question. But what are you using `~` to represent? In asp.net `~/` represents the root directory of the application, see [Slash (/) vs tilde slash (~/) in style sheet path](https://stackoverflow.com/q/6424114). Also, what versions are you using? Can you share a [mcve] that is clearer that your screen shots? [Tilde Slash Paths Not Working in MVC 4](https://stackoverflow.com/q/10853316) may be relevant. – dbc Dec 20 '22 at 19:39
  • @dbc, thanks for your comment. The issue is resolved. The article you attached is exactly what I was looking for. Please write your answer here, and I will accept it. :) thank you so much. – JShobbyist Dec 20 '22 at 20:04
  • Which article? "Tilde Slash Paths Not Working in MVC 4" or "Slash (/) vs tilde slash (~/) in style sheet path." – dbc Dec 20 '22 at 20:05
  • "Slash (/) vs tilde slash (~/) in style sheet path.". : ) – JShobbyist Dec 20 '22 at 20:07
  • I've removed `~` from the code and it worked well. – JShobbyist Dec 20 '22 at 20:14
  • @dbc, are you familiar with git? if so, would you check [this question](https://stackoverflow.com/q/74827402/14912225) too? thanks. – JShobbyist Dec 20 '22 at 20:18

1 Answers1

0

I am adding this answer since dbc didn't want to leave the answer here even though I asked him to leave an answer. The solution is to remove ~ from the code. He provided a very helpful answer - Slash (/) vs tilde slash (~/) in style sheet path and it was a topic regarding ASP.NET and exactly what I was looking for. I resolved the issue. : )

JShobbyist
  • 532
  • 3
  • 9
  • 23