简体   繁体   中英

Asp.Net Core 3.1 references doesn't work because of tilde “~”

We use <link> to reference a file for CSS or other static files. like this:

    <link href="~/assets/css/style.bundle.css" rel="stylesheet" type="text/css" />

or to import a javascript library. like this:

<script src="~/libs/jquery/dist/jquery.js"></script>

The address of all these references starts with "~/..." which means the wwwroot folder.

When I run the project (on IIS Express or any other) these addresses being like this:

在此处输入图片说明

And it always works. I believe the browser doesn't understand address which starts with tilde "~". SO, at some point, something removes all ~ from addresses before sending the page to the browser.

recently, a cloned a repository that has a lot of CSS and js references. Non of "~" doesn't been removed when I run the project.

在此处输入图片说明

And the point is when I remove the "~" from the address in the inspector of chrome, the source being loaded and works properly.

I tried to delete them manually. but it caused a lot of other issues and errors.

What can I do to avoid sending "~" to the browser? or somehow solve this issue.

I'm not sure how helpful this "answer" might be, but I also ran across the same issue for an ASP.NET Core 2.1 solution. Nothing I did to the solution itself would resolve the issue, so I deleted my copy of the solution and re-cloned. Then it started working again for me.

I have no idea what the root cause was or why this would fix it, but hopefully it works for you/others too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM