IIS shows 404 but file exists
Asked Answered
H

8

9

I have issue with my app after run it on VPS.

I installed IIS on VPS, removed DefaultWebsite, and add another one. Everything looks fine, website starts, but I don't have access to any files from folders like Content, Scripts, Templates and so on. That's mean i don't have any pictures, and styles on my website.

I try to grand permissions for IIS_IUSRS but files still don't display correctly. Website is on on same partition as system, and i think that's the problem, but i can't move it. I have just one partition :-( Any solution for it?

Husking answered 29/12, 2016 at 14:11 Comment(2)
i have same issue. i was restart my pcLeaden
Check the Event Log to see if there's any permission issues being logged.Ostentation
U
8

None of the above worked for me. What did work (and I remember from eons gone by) is the lack of a MIME type mapping confuses IIS. This is easy to diagnose as the problem if you can put files of different types in different folders.

Easy fix is the "MIME Types" section under IIS, either on the server, web site, or virtual folder. Just add "*.foo" and "application/octet-stream" as the MIME type which says "just send the bytes already!"

Unlikely answered 17/2, 2020 at 2:17 Comment(2)
This is the solution that worked for me. I set my content type to application/octet-stream, and IIS served the file.Hypoacidity
A quick though very insecure fix to ensure that IIS serves so far unconfigured MIME types as "application/octet-stream" is to add a default MIME type in the config as detailed at https://mcmap.net/q/1316195/-iis7-default-mime-type-behavior. Remember though that this will make IIS serve every unrecognized type as an octet stream, leading to possible security compromises.Hypoacidity
U
1

You need to add a web.config file to serve static files in each folder that contains static files with the following content:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <staticContent>
            <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
        </staticContent>
        <handlers accessPolicy="Script,Read">
            <!-- For any request to a file exists on disk, return it via native http module. AccessPolicy="Script" above is to allow for a managed 404 page. -->
            <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" />
        </handlers>
    </system.webServer>
</configuration>
Unbecoming answered 29/12, 2016 at 14:21 Comment(5)
Unfortunately still same :-(Husking
Have you added it to all static content folders? And after that you need to reset IIS.Charlotte
Yes, all static content folders.Husking
Have you enabled "Static Content" under "Common HTTP Features" in the IIS settings when you installed IIS?Charlotte
It seems that the validateIntegratedModeConfiguration is hiding the issue, plrease refer to the validateIntegratedModeConfiguration docs: iis.net/configreference/system.webserver/validation > Because IIS will no longer provide warnings for unsupported configurations when validateIntegratedModeConfiguration is false, ensure that your application works correctly in Integrated mode before you make this setting.Charlotte
M
1

I found the solution here:

To use the UI:

  • Open IIS Manager and navigate to the level you want to manage. For information about opening IIS Manager, see Open IIS Manager (IIS 7). For information about navigating to locations in the UI, see Navigation in IIS Manager (IIS 7).
  • In Features View, double-click MIME Types.
  • In the Actions pane, click Add.
  • In the Add MIME Type dialog box, type a file name extension in the File name extension text box. For example, type .xyz.
  • Type a MIME type in the MIME type text box. For example, type application/octet-stream.
  • Click OK.
Mauriac answered 13/2 at 18:58 Comment(0)
A
0

Please check user in IIS. Site -> Basic Settings -> Connect as... (if I recall correctly)

By default user in IIS is IUSR. You have to change to IIS_IUSRS. And then Your permissions will work.

This Article could help you

Aborning answered 29/12, 2016 at 14:21 Comment(0)
H
0

I also have add this code to make app running. Without it app don't work, but files show correctly :-(

<system.webServer>
   <validation validateIntegratedModeConfiguration="false"/>
    <handlers>
   <remove name="BlockViewHandler"/>
     <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>
    </handlers>
    </system.webServer>
Husking answered 29/12, 2016 at 14:40 Comment(0)
L
0

In my case, I had a file with the extension cache - an unknown mime type within IIS.

My 404 file not found trouble was resolved by updating the site web.config to add mimeMap for file extension cache, as follows:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <directoryBrowse enabled="true" />
        <security>
            <requestFiltering>
                <fileExtensions>
                    <remove fileExtension=".config" />
                    <add fileExtension=".config" allowed="true" />
                    <add fileExtension=".dll" allowed="true" />
                    <add fileExtension=".exe" allowed="true" />
                </fileExtensions>
            </requestFiltering>
        </security>
        <handlers accessPolicy="Read, Script" />
        <staticContent>
            <mimeMap fileExtension=".cache" mimeType="text/plain" />
        </staticContent>
    </system.webServer>
</configuration>

More about Adding Static Content MIME Mappings and Troublshooting a 404

Locke answered 12/2, 2019 at 6:47 Comment(0)
E
0

Probably not a common problem, but I accidentally created a virtual directory with the path to my default page, and that messed things up. I had to open the applicationhost.config file, and delete the virtual directory (well, probably could have deleted it another way, but I didn't figure it out until I opened the file, and since I already had it open, I went ahead and saved the changes).

Elevation answered 11/3, 2021 at 21:46 Comment(0)
C
0

I also had this problem, it turned out to be file path problem.

I tried to access the path as "C:\folder\file"

When i tried to access it as "\file" it worked, so it is going to be like "(your server)\file"

Not "(your server)C:\folder\file"

Chamaeleon answered 22/9, 2022 at 18:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.