0

We have a published .NET Core 3.1 website hosted by IIS. The root folder (containing the DLLs) is: c:\qa\web\

Otherwise we have folders like:

  • c:\qa\web\wwwroot\css
  • c:\qa\web\wwwroot\js

In IIS we made a virtual directory named "images". The website can be access via http://localhost

We can view individual files without error:

  • http://localhost/js/brand.js
  • http://localhost/css/main.css

However we get a 404 when trying to view files in the virtual directory:

http://localhost/images/foo.jpg

But if we insert "/wwwroot" in the URL, we see the contents of the virtual directory without issue:

http://localhost/wwwroot/images/foo.jpg

Why do we need "wwwroot/" in the URL? When we run the same website from Visual Studio / IIS Express, we don't need "wwwroot/" in the URL to view /images/foo.jpg

I thought maybe if we set the Virtual Directory alias to "wwwroot/images" it might work, but it doesn't allow for the slash character in the alias.

1

2 Answers 2

0

Make sure that virtual directory is created at site level. It looks like it is nested in wwwroot folder. Try this - right click on site --> Add virtual directory --> Alias: images, Physical path: c:\qa\web\wwwroot. After this you should reach images under http://localhost/images/js/brand.js, http://localhost/images/css/main.css etc.

If it does't help, consider to keep static files in different folder outside the application root folder, and create virtual directory linked to it.

Sign up to request clarification or add additional context in comments.

3 Comments

It was created at the site-level.
Failed request tracking is a useful way to solve the problem.
@samwu until you have Windows 11 and no IE11 and can't view the output of FRT :(
0

For me, the static files are in a virtual directory. I had to add a web.config with:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <remove name="aspNetCore"/>
    </handlers>
  </system.webServer>
</configuration>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.