简体   繁体   中英

IIS deployment cannot contains files for wwwroot folder in asp.net core 2.2 razor pages

I have subfolders of JS and CSS in my wwwroot folder of asp.net core razor page application. Application works fine in local environment, but while deployment of the project on IIS, the wwwroot folder does not contain any subfolders or files in it.

Even if I manually upload the folders and files to wwwroot folder, it doesn't work and it does not load the JS and CSS files in the browser.

Note that I do not have "Environment" tags in my application.

Try to edit the .csproj file of your asp.net core project:

Remove all the ItemGroup tags and their contents then add this

<ItemGroup>
    <None Include="wwwroot\*" />
</ItemGroup>

You could refer this link for more detail:

Visual Studio publish profiles for ASP.NET Core app deployment

There are two ways of setting the js/css path

  1. Absolute Path
  2. Relative Path

Absolute Path is, you have to give proper path in web server .

http://<website name>/css/site.css

Relative Path is, you can give file page relative to current page.

let say your page is from http://<website name>/index.html relative path will be ./css/site.css

Better you try to access js or css file from browser. may be these folders do not have right permission to access.

if you open Dev Tool, you can see the error in Network tab or console. Base on HTTP code, you can decide what has happened

In my scenario I was adding MVC to my .Net 5 API

The solution was to add

 app.UseStaticFiles();

to the Startup.cs

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