I am working on a asp.net core 2.2 project more than 1 year and it was working fine but recently I changed the the project working directory from user profile folder to C:\ Drive. Now, When I build the project it build successful but when I run the project using IIS Express in visual studio 2017, It flesh the error on browser. "Failed to load resource: the server responded with a status of 404 (Not Found) error in server" for all JS/CSS/Image files in wwwroot directory and the path of static files are not resolving. enter image description here

I also tested same with one more new project and same is happing with new one.

Although at same configuration on my colleague machine everything is working fine.

I checked all possible configuration files with my colleague machine and it seems good and same.

What I checked till now with lots of R&D that din work for me are below.

My Current Core SDK framework is 2.2.110 and Visual studio is 2017.

1.vs>>applicationhost.config

2.App setting

3.web config

4.launch setting

5.change startup configure method like:
app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), "wwwroot")), RequestPath = "/wwwroot" } );

6.changed Program File method WebHost.CreateDefaultBuilder(args).UseWebRoot(Path.Combine(AppContext.BaseDirectory, "wwwroot"))

7.IIS express applicationhost.config

<site name="FISSurvey" id="3">
                <application path="/" applicationPool="Clr4IntegratedAppPool">
                    **<virtualDirectory path="/" physicalPath="C:\Projects\Pulse2.0\Pulsev3.4\FISSurvey" />**
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation="*:55892:localhost" />
                    **<binding protocol="https" bindingInformation="*:44352:localhost" />**
   </bindings>
</site>

and many other things suggested on R&D but still problem is same.

Some has suggested remove "~/" from JS-CSS-Image path. But in my current project it won't be possible as is working fine for other team member with same path and change would affect them as we are working on same project and can't remove "~/" as it was working fine prior to change directory.

I have doubt there is something missing at machine level or visual studio configuration or some setting has changed that IIS Express unable to resolve.

Please suggest how could I overcome with this problem. Thanks in advance.

1

There are 1 best solutions below

0
Leo.T On

After a year, no one replied nor closed the post. So I still can answer it , right?

The default path for static files is {path to the project}\wwwroot.

But when using debugger of visual studio, the path will be {path to the project}\bin\{configuration manager's solution configuration}\{version of .net core}\wwwroot.

For example: C:\MyApp\bin\Debug\netcoreapp3.1\wwwroot

When press F5 to debug, the static files may not copy to the the debugger folder. It causes the links of static files display as "Not found(404)".

Solution 1: Manually copy the wwwroot folder from the project folder to the debug folder .

Solution 2: Open Solution Explorer. Right-click on static files and click the property column. Check the column of "copy to output directory", choose always copy.