admin管理员组文章数量:1312895
I have a website that I prepared using .NET 8. This site worked fine both on my local computer during the testing phase and on the real server on the subdomain. I had no problems for days.
However, when I publish it in the same way and upload it to the main domain, the style files and images do not load properly. When the page is first opened, everything appears shifted. If I refresh the page, some more styles and images are loaded.
After the 5th or 6th refresh, it loads properly. Moreover, when I enter the same browser a few hours later, the same problem occurs again. I tried many ways but there was no solution.
The path of the files is correct. When I examine it in the browser console, it gives a 403 error for the files that are not loaded, but if I click on the link and say open, that file opens. I already said that the files came when I refreshed.
I'm really fed up with this, your help would make me very happy.
My experiments:
I also wrote the paths of the files in different ways. I did it by starting with
~/assets
, or evenhref='@Url.Content("~/Content/lib/bootstrap/dist/css/bootstrap.min.css")'
.I moved the theme files under the
Content
folder and updated the pathsI added preload property to the style files
I also tried adding lazy load to the image files
I made various settings in my
program.cs
file, such as the code shown below.builder.Services.AddCors(options => { options.AddDefaultPolicy( policy => { policy.AllowAnyOrigin() .AllowAnyHeader() .AllowAnyMethod(); }); }); // ... app.UseCors(); app.UseStaticFiles();
All
wwwroot
directory, its sub directories and files have permission of read and listI checked the mime types in the plesk panel, they are all attached
I published project as debug instead of release
After publishing, I added the following settings to the
web.config
file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\Proje.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
<!-- Statik Files Caching -->
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
<remove fileExtension=".woff2"/>
<mimeMap fileExtension=".woff2" mimeType="font/woff2"/>
<mimeMap fileExtension=".css" mimeType="text/css" />
<mimeMap fileExtension=".js" mimeType="application/javascript" />
<mimeMap fileExtension=".png" mimeType="image/png" />
<mimeMap fileExtension=".jpg" mimeType="image/jpeg" />
</staticContent>
<httpCompression>
<dynamicTypes>
<add mimeType="text/css" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="font/woff2" enabled="true" />
</dynamicTypes>
</httpCompression>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</location>
</configuration>
The same site still works fine on the local computer and subdomain. The only difference I can think of between the subdomain and the main domain is SSL. SSL is installed on the main domain.
There aren't many settings in Plesk regarding SSL anyway. Even if I call an image or style file as http://
, it automatically turns into https://
. I think it's working properly.
本文标签: cNET 8 website style and image files are not loading properly when first loadedStack Overflow
版权声明:本文标题:c# - .NET 8 website style and image files are not loading properly when first loaded - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741878529a2402610.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论