asp.net-mvc ASP.NET MVC: 404 - 找不到文件或目录。您正在寻找的资源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23251900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 03:39:27  来源:igfitidea点击:

ASP.NET MVC: 404 - File or directory not found. The resource you are looking for

asp.net-mvciis-7windows-server-2003

提问by Charles

I recently deployed an ASP.NET MVC application on a Win server 2008, IIS 7 machine. It has MVC installed, and .NET framework 4.5 installed. Whenever I publish, and try to log in, I get this annoying error:

我最近在 Win server 2008、IIS 7 机器上部署了一个 ASP.NET MVC 应用程序。它安装了 MVC,并安装了 .NET framework 4.5。每当我发布并尝试登录时,都会遇到这个烦人的错误:

404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed, or is     temporarily unavailable.

Meanwhile the controller action - Home/Login is intact and the Login.cshtml page is okay. Plus the web config file has

同时控制器操作 - Home/Login 完好无损,Login.cshtml 页面正常。加上 web 配置文件有

  modules runAllManagedModulesForAllRequests="true"/>
  compilation debug="true" targetFramework="4.5">
  assemblies>
     handlers>
    remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit"/>
    remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit"/>
    remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
    add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule"  
    /handlers>

So I am wondering what is wrong. It is running under Integrated mode, ASP.NET 4.0 app pool. Static content and dynamic content are both enabled. I guess you can tell I have gone through most of the posts on this issue.:) Thanks in advance for the answer.

所以我想知道出了什么问题。它在集成模式下运行,ASP.NET 4.0 应用程序池。静态内容和动态内容均已启用。我想您可以看出我已经阅读了有关此问题的大部分帖子。:) 在此先感谢您的回答。

采纳答案by mmilleruva

If possible, I would log onto the server that is hosting the application, Open IIS Manager, find your site and click view in browser. This will ensure that you have the URL correct and should give you more debugging information if something is going wrong.

如果可能,我会登录到托管应用程序的服务器,打开 IIS 管理器,找到您的站点并在浏览器中单击查看。这将确保您拥有正确的 URL,并在出现问题时为您提供更多调试信息。

回答by dagelf

You might have to add MIME Types if your files have nonstandard extensions.

如果您的文件具有非标准扩展名,您可能需要添加 MIME 类型。

Fair choices:

公平的选择:

application/octet-stream
text/plain 

Without an associated MIME type, IIS just says 404 when you try and download a file which you can clearly see in the directory listing.

如果没有关联的 MIME 类型,当您尝试下载可以在目录列表中清楚看到的文件时,IIS 只会显示 404。

回答by Ganapathy T

I have added below MIME types to web.config under system.webserver, and it's working

我已将以下 MIME 类型添加到 system.webserver 下的 web.config,并且它正在工作

<urlCompression doStaticCompression="true" doDynamicCompression="true" />
    <httpCompression>
      <dynamicTypes>
        <clear />
        <add enabled="true" mimeType="text/*" />
        <add enabled="true" mimeType="message/*" />
        <add enabled="true" mimeType="application/x-javascript" />
        <add enabled="true" mimeType="application/javascript" />
        <add enabled="true" mimeType="application/json" />
        <add enabled="false" mimeType="*/*" />
        <add enabled="true" mimeType="application/atom+xml" />
        <add enabled="true" mimeType="application/atom+xml;charset=utf-8" />
      </dynamicTypes>
      <staticTypes>
        <clear />
        <add enabled="true" mimeType="text/*" />
        <add enabled="true" mimeType="message/*" />
        <add enabled="true" mimeType="application/javascript" />
        <add enabled="true" mimeType="application/atom+xml" />
        <add enabled="true" mimeType="application/xaml+xml" />
        <add enabled="true" mimeType="application/json" />
        <add enabled="false" mimeType="*/*" />
      </staticTypes>
    </httpCompression>