简体   繁体   English

IIS 显示 404 但文件存在

[英]IIS shows 404 but file exists

I have issue with my app after run it on VPS.我的应用在 VPS 上运行后出现问题。

I installed IIS on VPS, removed DefaultWebsite, and add another one.我在 VPS 上安装了 IIS,删除了 DefaultWebsite,并添加了另一个。 Everything looks fine, website starts, but I don't have access to any files from folders like Content , Scripts , Templates and so on.一切看起来都很好,网站启动了,但我无法访问ContentScriptsTemplates等文件夹中的任何文件。 That's mean i don't have any pictures, and styles on my website.这意味着我没有任何图片,并且我的网站上没有 styles。

I try to grand permissions for IIS_IUSRS but files still don't display correctly.我尝试为 IIS_IUSRS 授予权限,但文件仍然无法正确显示。 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?我只有一个分区:-(有什么解决方案吗?

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.什么起作用(我记得很久以前)是缺少 MIME 类型映射使 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.简单的修复是 IIS 下的“MIME 类型”部分,无论是在服务器、网站还是虚拟文件夹上。 Just add "*.foo" and "application/octet-stream" as the MIME type which says "just send the bytes already!"只需添加“*.foo”和“application/octet-stream”作为 MIME 类型,表示“已经发送字节!”

Please check user in IIS.请在 IIS 中检查用户。 Site -> Basic Settings -> Connect as... (if I recall correctly)站点 -> 基本设置 -> 连接为...(如果我没记错的话)

By default user in IIS is IUSR.默认情况下,IIS 中的用户是 IUSR。 You have to change to IIS_IUSRS.您必须更改为 IIS_IUSRS。 And then Your permissions will work.然后您的权限将起作用。

This Article could help you 这篇文章可以帮到你

You need to add a web.config file to serve static files in each folder that contains static files with the following content:您需要添加一个web.config文件来为每个包含以下内容的静态文件的文件夹中的静态文件提供服务:

<?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>

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>

In my case, I had a file with the extension cache - an unknown mime type within IIS.就我而言,我有一个带有扩展cache的文件 - IIS 中未知的 MIME 类型。

My 404 file not found trouble was resolved by updating the site web.config to add mimeMap for file extension cache , as follows:通过更新站点 web.config 为文件扩展cache添加 mimeMap 解决了我的 404 file not found 问题,如下所示:

<?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有关添加静态内容 MIME 映射404 故障排除的更多信息

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).我不得不打开 applicationhost.config 文件,并删除虚拟目录(好吧,可能可以通过其他方式删除它,但直到我打开文件才弄清楚,因为我已经打开了它,我去了并保存更改)。

I also had this problem, it turned out to be file path problem.我也遇到了这个问题,原来是文件路径问题。

I tried to access the path as "C:\folder\file"我试图以“C:\folder\file”的形式访问路径

When i tried to access it as "\file" it worked, so it is going to be like "(your server)\file"当我尝试以“\file”的形式访问它时,它起作用了,所以它就像“(你的服务器)\file”

Not "(your server)C:\folder\file"不是“(您的服务器)C:\folder\file”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 访问 IIS 中的 .svc 文件时出现 HTTP 404 - HTTP 404 when accessing .svc file in IIS File.Exists()始终在IIS上返回false - File.Exists() always returns false on IIS File.exists()在localhost中工作,但在IIS 7.5中不工作 - File.exists() working in localhost but not in IIS 7.5 DownloadFileAsync显示为已完成,但指定目录中不存在任何文件 - DownloadFileAsync shows as completed but no file exists in specified directory 找不到引发HTTP 404的IIS,但是资源存在。 要求的网址也会自动更改。 - IIS throwing HTTP 404 not found but resource exists. Requested URL also changing automatically.! 即使文件不存在,File.exists也会显示该文件 - File.exists shows file even when it does not exist IIS错误404甚至文件已存在,aspx正常打开 - IIS error 404 even file existsn, aspx opens normally IIS服务器找不到index.aspx文件-404错误 - IIS server can not find index.aspx file - 404 error asp.net中的文件上传显示404错误 - file upload in asp.net shows 404 error WebApi,文件存在但未找到文件,IIS始终从“ C:\\ Program Files(x86)\\ IIS Express”文件夹中读取 - WebApi, File exists but file not found, IIS always reads from “C:\Program Files (x86)\IIS Express” folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM