简体   繁体   English

在 IIS 7.5 中托管的 Web Api 中找不到 HTTP 404 页面

[英]HTTP 404 Page Not Found in Web Api hosted in IIS 7.5

I have a Web Api application.我有一个 Web Api 应用程序。 It works perfectly well when I tested it using the VS 2010 debugging dev server.当我使用 VS 2010 调试开发服务器对其进行测试时,它运行良好。 But I now deployed it to IIS 7.5 and I am getting a HTTP 404 error when trying to access the application.但是我现在将它部署到 IIS 7.5 并且在尝试访问应用程序时出现 HTTP 404 错误。

Here is my web.config这是我的 web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-FlowGearProxy-20123141219;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="true" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>

I was struggling with this as well.我也为此苦苦挣扎。 Fortunately, Steve Michelotti documented a solution that worked for me here .幸运的是,Steve Michelotti 在这里记录了一个对我有用的解决方案。

At the end of the day, I enabled all verbs (verb="*") to the ExtensionlessUrlHandler-Integrated-4.0 handler in my web config.在一天结束时,我在 Web 配置中为 ExtensionlessUrlHandler-Integrated-4.0 处理程序启用了所有动词(动词 =“*”)。

<system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
        <handlers>
            <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
            <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
        </handlers>
</system.webServer>

Others have pointed out that having WebDAV enabled causes issues.其他人指出启用 WebDAV 会导致问题。 Fortunately, I did not run into that issue as well.幸运的是,我也没有遇到这个问题。

Had same issue.有同样的问题。 This configuration setting solved the issue.此配置设置解决了该问题。

<system.webServer>
    .....
    <modules runAllManagedModulesForAllRequests="true" />
    .....
</system.webServer>

As explained in http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html above solution should be avoided.http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html 中所述,应避免使用上述解决方案。 Use this instead.改用这个。 Same solution is provided by Lopsided also. Lopside 也提供了相同的解决方案。 Keeping it here to let users avoid implementing the first working solution.将其保留在这里是为了让用户避免实施第一个可行的解决方案。

<modules>
  <remove name="UrlRoutingModule-4.0" />
  <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  <!-- any other modules you want to run in MVC e.g. FormsAuthentication, Roles etc. -->
</modules>

If IIS is installed or enabled after ASP.NET, you will need to manually register ASP.NET with IIS in order for your .NET application to work.如果在 ASP.NET 之后安装或启用了 IIS,您将需要手动向 IIS 注册 ASP.NET,以便您的 .NET 应用程序工作。

For Windows 7 and earlier:对于 Windows 7 及更早版本:

  1. Run the Command Prompt (cmd.exe) as an administrator.以管理员身份运行命令提示符 (cmd.exe)。
  2. Navigate to the appropriate .NET Framework location.导航到相应的 .NET Framework 位置。 (eg C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319) (例如 C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319)
  3. Run aspnet_regiis.exe -i运行aspnet_regiis.exe -i

For Windows 8 and later:对于 Windows 8 及更高版本:

  1. From the start menu, type "Turn windows features on or off" and select the first result.从开始菜单中,键入“打开或关闭 Windows 功能”并选择第一个结果。
  2. Expand Internet Information Services: World Wide Web Services: Application Development Features and select ASP.NET 4.5 (or ASP.NET 3.5 if you need to support projects on .NET Framework 2.0-3.5).展开 Internet 信息服务:万维网服务:应用程序开发功能并选择 ASP.NET 4.5(如果需要支持 .NET Framework 2.0-3.5 上的项目,则选择 ASP.NET 3.5)。
  3. Click OK.单击确定。

Are you running the Web API app in a virtual directory or an application?您是在虚拟目录还是应用程序中运行 Web API 应用程序?

For example: I had the same issue when I moved my project to my local IIS under the Default Web Site > SampleWebAPI.例如:当我将项目移动到默认网站 > SampleWebAPI 下的本地 IIS 时,我遇到了同样的问题。 I believe this is due to the change in the URL routing as follows:我相信这是由于URL路由的变化如下:

Original: localhost:3092/api/values原文: localhost:3092/api/values
Moved: localhost/SampleWebAPI/api/values移动: localhost/SampleWebAPI/api/values

If you move the Web API project to it's own website running on a different port it seems to work.如果您将 Web API 项目移动到它自己在不同端口上运行的网站,它似乎可以工作。

Additional note: I had further complicated the issue by adding api as the alias of an application within my website which caused the effective URL to be:附加说明:我通过在我的网站中添加api作为应用程序的别名使问题进一步复杂化,这导致有效URL为:

localhost:81/api/api/values - noticed this after moving the website to it's own website localhost:81/api/api/values - 将网站移至自己的网站后注意到这一点

Therefore, because I wanted to maintain a separation between my website and the web api mvc project site, I changed the routing rules in global.asax for the Web API "DefaultAPI" from api/{controller}/{id} to {controller}/{id} and the ASP.NET MVC one Default from {controller}/{id} to info/{controller}/{id} .因此,因为我想保持我的网站和 web api mvc 项目站点之间的分离,我将global.asax中 Web API“DefaultAPI”的路由规则从api/{controller}/{id}更改为{controller}/{id}和 ASP.NET MVC 一个Default{controller}/{id}info/{controller}/{id}

This is the only answer that worked for me...这是唯一对我有用的答案......

I had a similar issue... It seemed like no matter what I did, nothing was getting redirected and my global file was just being ignored.我有一个类似的问题......似乎无论我做什么,都没有重定向,我的全局文件只是被忽略了。 I seriously considered just ending it all before I found this answer.在找到这个答案之前,我认真考虑过结束这一切。 I hope this link helps somebody else.我希望这个链接可以帮助其他人。


Adding the following to the web.config file worked for me:将以下内容添加到 web.config 文件对我有用:

<system.webServer>
  <modules>
    <remove name="UrlRoutingModule-4.0" />
    <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
  </modules>
</system.webServer>

system.webServer tag was already there of course but I added the modules tag to it and then the remove & add tags to modules tag. system.webServer标签当然已经存在,但我添加了模块标签,然后删除添加标签到模块标签。

A few things to check:需要检查的几件事:

  1. Make sure that you have the .NET Framework 4 installed.确保您已安装 .NET Framework 4。
  2. Ensure that version 4 of the .NET Framework is selected for your website & virtual directory (if applicable).确保为您的网站和虚拟目录(如果适用)选择了 .NET Framework 版本 4。
  3. Ensure that you have MVC installed or have the appropriate DLLs in your bin directory.确保您已安装 MVC 或在您的 bin 目录中有适当的 DLL。
  4. Might need to allow ASP.NET 4.0 web service extensions可能需要允许 ASP.NET 4.0 Web 服务扩展
  5. Put the application in it's own app pool.将应用程序放在它自己的应用程序池中。
  6. Make sure the directory has at least "Scripts Only" execute permissions.确保目录至少具有“仅脚本”执行权限。

I had a similar problem.我有一个类似的问题。 I had the right settings in my web.config file but was running the application pool in Classic mode rather than Integrated mode我在 web.config 文件中有正确的设置,但在经典模式而不是集成模式下运行应用程序池

截屏

This issue can also happen due to the following由于以下原因也可能发生此问题

1.In the Web.Config 1.在Web.Config中

<system.webServer>
     <modules runAllManagedModulesForAllRequests="true" /> 
<system.webServer>

2.Make sure the following are available in the bin folder on the server where the Web API is deployed 2.确保部署Web API的服务器上的bin文件夹中有以下内容

  • System.Net.Http系统.Net.Http

  • System.Net.Http.Formatting System.Net.Http.Formatting

  • System.Web.Http.WebHost系统.Web.Http.WebHost

  • System.Web.Http系统.Web.Http

These assemblies won't be copied in the bin folder by default if the publish is through Visual Studio because the Web API packages are installed through Nuget in the development machine.如果通过 Visual Studio 发布,则默认情况下不会将这些程序集复制到 bin 文件夹中,因为 Web API 包是通过开发计算机中的 Nuget 安装的。 Still if you want to achieve these files to be available as part of Visual Studio publish then you need to set CopyLocal to True for these Assemblies尽管如此,如果您想让这些文件作为 Visual Studio 发布的一部分可用,那么您需要将这些程序集的 CopyLocal 设置为 True

Sadish Kumar.V萨迪什·库马尔.V

Based on this SO answer , I just had to change path="*."基于这个SO answer ,我只需要更改path="*." to path="*" for the added ExtensionlessUrlHandler-Integrated-4.0 in configuration>system.WebServer>handlers in my web.config在我的web.config中的configuration>system.WebServer>handlers中添加ExtensionlessUrlHandler-Integrated-4.0path="*"

Before:前:

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

After:后:

<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

I also ran into this problem.我也遇到了这个问题。 I solved the problem by going to the Application Pools > Application Pool Name and changed the .NET Framework from version v.2.0.50727 to v4.0.30319.我通过转到应用程序池 > 应用程序池名称解决了这个问题,并将 .NET Framework 从版本 v.2.0.50727 更改为 v4.0.30319。

我不得不禁用文件发布选项“发布期间预编译”。

There is official fix from microsoft: http://support.microsoft.com/kb/980368微软有官方修复: http : //support.microsoft.com/kb/980368

I strongly do NOT recommend to use < modules runAllManagedModulesForAllRequests="true">.我强烈不推荐使用 < modules runAllManagedModulesForAllRequests="true">。 This leads all requests (even .jpg, .css, .pdf, etc) will be processed by all registered HTTP modules.这导致所有请求(甚至 .jpg、.css、.pdf 等)都将由所有已注册的 HTTP 模块处理。 There are two negative moments: a) additional load on hardware resources;有两个负面时刻:a) 额外的硬件资源负载; b) potential errors, as http modules will process new type of content. b) 潜在错误,因为 http 模块将处理新类型的内容。

I started getting 404 responses from Web API after following a Windows Azure tutorial that told me to add a file "WebRole.cs" to my project.在遵循 Windows Azure 教程后,我开始从 Web API 获得 404 响应,该教程告诉我将文件“WebRole.cs”添加到我的项目中。

After removing "WebRole.cs" from my project, my Web API calls started working again.从我的项目中删除“WebRole.cs”后,我的 Web API 调用又开始工作了。

Please make sure the application pool is in Integrated mode请确保应用程序池处于集成模式
And add the following to web.config file:并将以下内容添加到 web.config 文件中:

<system.webServer>
    .....
    <modules runAllManagedModulesForAllRequests="true" />
    .....
</system.webServer>

In my case, the issue was simply that I was trying to access the site at就我而言,问题只是我试图访问该网站

myserver.myintranet.com/mysite

But the web site binding for http in IIS didn't have the host name specified in the binding.但是 IIS 中 http 的网站绑定没有在绑定中指定的主机名。 It had worked before and I have no idea how that got blown away.它以前有效,我不知道它是如何被吹走的。

Once I put myserver.myintranet.com into the host name the 404 was gone.一旦我将myserver.myintranet.com放入主机名,404 就消失了。

In IIS Manager you go into Bindings... in the actions pane, then edit the http binding to specify the host name.在 IIS 管理器中,您进入操作窗格中的绑定... ,然后编辑 http 绑定以指定主机名。

不要忘记部署 global.asax

Had the same issue, a 404 response for the web api controllers when served from the IIS but everything worked fine from VS2010.有同样的问题,当从 IIS 提供服务时,web api 控制器的 404 响应,但在 VS2010 中一切正常。 None of the above solutions worked for me.以上解决方案都不适合我。 Eventually I found that the problem was that we added WSE 3.0 support for the application and the Microsoft.Web.Services3 dll was missing in the application's /bin directory.最终我发现问题在于我们为应用程序添加了 WSE 3.0 支持,而应用程序的 /bin 目录中缺少 Microsoft.Web.Services3 dll。 Weird, but after copying the dll, the route mapping started to work.奇怪,但是复制dll后,路由映射开始工作。

I struggled with this, as well.我也为此苦苦挣扎。 My exact issue was that I had an ASMX Web Service that, when I entered a parameter into a web method and tested it, then it would give me the 404. The particular method had worked fine in the past and hadn't been changed, only re-published.我的确切问题是我有一个 ASMX Web 服务,当我在一个 Web 方法中输入一个参数并对其进行测试时,它会给我 404。特定的方法在过去运行良好并且没有改变,只能重新发布。 Then I got here and tried all of the posted answers & nothing helped.然后我到了这里并尝试了所有发布的答案,但没有任何帮助。

My ultimate solution?我的终极解决方案? I know this is drastic, but I just created a new Visual Studio solution and web project.我知道这很严重,但我刚刚创建了一个新的 Visual Studio 解决方案和 Web 项目。 Selected MVC, then I did an "Add" > "New Item", selected "Visual C#" > "Web" and "Web Service (ASMX)" under that.选择MVC,然后我做了一个“添加”>“新项目”,在它下面选择了“Visual C#”>“Web”和“Web Service (ASMX)”。 I copied all of my old code-behind code, then I took note of the namespace it gave the new file in my new project, then pasted all of my old code into the new code-behind file in the new project and put the namespace back to what it had been.我复制了所有旧的代码隐藏代码,然后记下它在新项目中为新文件提供的命名空间,然后将所有旧代码粘贴到新项目中的新代码隐藏文件中并放置命名空间回到原来的样子。

Then I created my folders in my project that I had before using Visual Studio to do "Add" > "New Folder", then copied back in my files into the folders from my other project using Windows Explorer, then right-clicked each folder in Visual Studio and did "Add" > "Existing Item..." and pulled the items in those folders into my new project's Visual Studio folders.然后,我在使用 Visual Studio 执行“添加”>“新建文件夹”之前的项目中创建了我的文件夹,然后使用 Windows 资源管理器将我的文件复制回其他项目的文件夹中,然后右键单击其中的每个文件夹Visual Studio 并执行“添加”>“现有项目...”并将这些文件夹中的项目拉入我的新项目的 Visual Studio 文件夹中。 I referenced all my .NET assemblies again, having both projects open so I could compare which ones I had referenced, previously (there were several).我再次引用了我所有的 .NET 程序集,打开了两个项目,这样我就可以比较我之前引用的那些(有几个)。 I had to name my new project slightly different - basically I did something comparable to "GeneralWebApp" instead of "MyWebApp", for example - so I had to do a "Replace All" in my whole solution to replace that name, so it would get the right namespace for all my files.我不得不为我的新项目命名略有不同——例如,基本上我做了一些类似于“GeneralWebApp”而不是“MyWebApp”的事情——所以我不得不在我的整个解决方案中做一个“全部替换”来替换那个名称,所以它会为我的所有文件获取正确的命名空间。

Then I did a "Rebuild All" on the project, then started it up with the "Play" button Visual Studio gives when I got it to build correctly.然后我对项目进行了“全部重建”,然后使用 Visual Studio 在正确构建时提供的“播放”按钮启动它。 It worked fine.它工作得很好。 So I published it, and everything was fine on the server where I published it, when I ran it from there.所以我发布了它,当我从那里运行它时,我发布它的服务器上的一切都很好。 I have no explanation as to what happened, but that's how I got through it.我无法解释发生了什么,但我就是这样度过的。 It's not a bad test just to see if something Visual Studio is doing has mucked it up.这不是一个糟糕的测试,只是为了看看 Visual Studio 正在做的事情是否把它搞砸了。

For me the problem was the root site was configured to use a .NET 2.0 app pool, and my application within that site was .NET 4.5.对我来说,问题是根站点配置为使用 .NET 2.0 应用程序池,而我在该站点中的应用程序是 .NET 4.5。

I created a new site with a .NET 4 app pool and placed my application at the root of that - and that worked fine.我创建了一个带有 .NET 4 应用程序池的新站点,并将我的应用程序放置在它的根目录下 - 效果很好。

If you place only the bin folder in IIS (after building the project), this problem will be occurred too.如果只将bin文件夹放在IIS中(建好工程后),也会出现这个问题。 In this situation you should publish the project using VisualStudio, then place the published folder into IIS.在这种情况下,您应该使用 VisualStudio发布项目,然后将发布的文件夹放入 IIS。

This piece of configuration in web.config file can help as helped to me: in the system.webServer section: web.config 文件中的这段配置对我有帮助:在 system.webServer 部分:

      <security>
          <requestFiltering>
              <verbs applyToWebDAV="true">
                  <remove verb="PUT" />
                  <add verb="PUT" allowed="true" />
                  <remove verb="DELETE" />
                  <add verb="DELETE" allowed="true" />
                  <remove verb="PATCH" />
                  <add verb="PATCH" allowed="true" />
              </verbs>
          </requestFiltering>
      </security>      

I recently had a 404 not found error with all my Web Api 2 routes/controllers.最近,我的所有 Web Api 2 路由/控制器都出现了 404 not found 错误。 So I went onto the actual server and tried to browse using localhost instead of the hostname and got "404.7 Not Found - The request filtering module is configured to deny the file extension".因此,我进入实际服务器并尝试使用 localhost 而不是主机名进行浏览,并得到“404.7 Not Found - 请求过滤模块配置为拒绝文件扩展名”。

This SO post help me solve it. 这篇SO帖子帮我解决了它。

It got resolved for me, when I enable checkbox for UrlRoutingModule-4.0:当我为 UrlRoutingModule-4.0 启用复选框时,它为我解决了:

IIS Manager > Modules > select UrlRoutingModule-4.0 > Edit Module > check the check-box "Invoke only for requests to ASP.NET applications or managed handlers". IIS 管理器 > 模块 > 选择 UrlRoutingModule-4.0 > 编辑模块 > 选中复选框“仅针对对 ASP.NET 应用程序或托管处理程序的请求调用”。

I had the same issue: on a newly installed machine with Visual Studio 2013, the web api project was working under IISExpress, but not under local IIS.我有同样的问题:在新安装的带有 Visual Studio 2013 的机器上,web api 项目在 IISExpress 下工作,但不在本地 IIS 下。 I tried everything I could find, but in the end the problem was not necessary with Web API, but with MVC: even it was installed, no MVC project was running.我尝试了我能找到的所有方法,但最终问题不是 Web API 所必需的,而是 MVC 所必需的:即使安装了它,也没有 MVC 项目在运行。

What worked for me was to uninstall IIS (from ADD/REMOVE Windows Features), then reinstall it, and then run aspnet_regiis -i.对我有用的是卸载 IIS(从添加/删除 Windows 功能),然后重新安装它,然后运行 ​​aspnet_regiis -i。 Maybe this helps somebody else.也许这对其他人有帮助。

I spent lot's of time trying a lot of things to finally realise I was adding my web app not in Sites/Default Web Sites, but in another website binded to another port.我花了很多时间尝试了很多事情,最终意识到我不是在站点/默认网站中添加我的网络应用程序,而是在绑定到另一个端口的另一个网站中。 Obviously trying localhost on port 80 would give a 404.显然,在端口 80 上尝试 localhost 会得到 404。

i do nothing, just add this tag in web.config, its working this issue come up one of the following points我什么都不做,只是在 web.config 中添加这个标签,它的工作这个问题出现以下几点之一

  1. Use Web Api in the same project using MVC or asp.net forms在同一项目中使用 MVC 或 asp.net 表单使用 Web Api

  2. Use RouteConfig and WebApiConfig in Global.asax as GlobalConfiguration.Configure(WebApiConfig.Register);在 Global.asax 中使用 RouteConfig 和 WebApiConfig 作为 GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); RouteConfig.RegisterRoutes(RouteTable.Routes);

  3. Use RouteConfig for 2 purposes, asp.net forms using with friendlyurl and mvc routing for MVC routing将 RouteConfig 用于 2 个目的,asp.net 表单使用friendlyurl 和 mvc 路由用于 MVC 路由

we just use this tag in web.config, it will work.我们只是在 web.config 中使用这个标签,它会起作用。

<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
   .........................
</modules>
</system.webServer>

Ran into the same issue with Web API and .Net Core Web API. Web API 和 .Net Core Web API 遇到了同样的问题。 Worked fine in VS 2017 while debugging, but returned 404 when published to IIS 7.5.调试时在 VS 2017 中运行良好,但在发布到 IIS 7.5 时返回 404。 Solution for me was to change the way I created the site.我的解决方案是改变我创建网站的方式。 Instead of publishing to the root of a Web Site (created by right clicking Sites...Add Web Site), I had to create an Application (created by right clicking a Web Site...Add Application) and publish to that folder.而不是发布到网站的根目录(通过右键单击站点...添加网站创建),我必须创建一个应用程序(通过右键单击网站...添加应用程序创建)并发布到该文件夹​​。 Note that for the Core version, I had to change the Application Pool .NET Framework Version setting to "No Managed Code".请注意,对于 Core 版本,我必须将 Application Pool .NET Framework Version 设置更改为“No Managed Code”。

For me the solution was removing the following lines from my web.config file:对我来说,解决方案是从我的 web.config 文件中删除以下几行:

<dependentAssembly>
    <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.1.3" newVersion="4.1.1.3" />
</dependentAssembly>
<dependentAssembly>
    <assemblyIdentity name="Microsoft.IdentityModel.Tokens" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.5.0.0" newVersion="5.5.0.0" />
</dependentAssembly>

I noticed that VS had added them automatically, not sure why我注意到 VS 自动添加了它们,不知道为什么

Try this webconfg.. replace "NewsApi.dll" with your main dll!试试这个 webconfg.. 用你的主 dll 替换“NewsApi.dll”!


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\NewsApi.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    </system.webServer>
  </location>
</configuration>

This is a really obvious answer/rookie mistake, but I thought I would just put it here in case it might help someone.这是一个非常明显的答案/新手错误,但我想我会把它放在这里以防它可能对某人有所帮助。 So my structure was that a had a Website in IIS with the frontend as one application underneath the website and the backend was the other.所以我的结构是在 IIS 中有一个网站,前端作为网站下的一个应用程序,后端是另一个。 The backend application had six seperate api applications sitting beneath it.后端应用程序下面有六个单独的 api 应用程序。 I had forgotten to convert each of the api folders to applications within IIS and of course this was causing the routes to my api endpoints to return a 404.0 error.我忘记将每个 api 文件夹转换为 IIS 中的应用程序,当然这导致到我的 api 端点的路由返回 404.0 错误。

My Point: Check the simple stuff first!我的观点:首先检查简单的东西! Make sure that you have converted all folders to applications in IIS where that is required for your website to function correctly.确保您已将所有文件夹转换为 IIS 中的应用程序,这是您的网站正常运行所必需的。

I had a similar issue because I did not define routing correctly for web api.我有一个类似的问题,因为我没有为 web api 正确定义路由。 Here is my solution:这是我的解决方案:

public class Global : System.Web.HttpApplication { void Application_Start(object sender, EventArgs e) { GlobalConfiguration.Configuration.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = System.Web.Http.RouteParameter.Optional } );

 }

These pages helped me:这些页面帮助了我:

https://docs.microsoft.com/en-us/previous-versions/aspnet/hh834746(v=vs.118)?redirectedfrom=MSDN https://docs.microsoft.com/en-us/previous-versions/aspnet/hh834746(v=vs.118)?redirectedfrom=MSDN

https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/configuring-aspnet-web-api https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/configuring-aspnet-web-api

None of the above worked for me.以上都不适合我。 Finally it wasn't anything related to any configuration.最后,它与任何配置无关。

I was getting the 404 error while trying to run a debug session through Visual Studio 2017 using the built in IISExpress 10.0.我在尝试使用内置的 IISExpress 10.0 通过 Visual Studio 2017 运行调试会话时遇到 404 错误。 For me it was working when the release was published to the IIS server but getting a 404 when debugging locally through VS.对我来说,当发布发布到 IIS 服务器时它正在工作,但在通过 VS 本地调试时得到 404。

The issue turned out to be some old compiled files lying in the project bin directory which appeared to be interfering.问题原来是一些旧的编译文件位于项目 bin 目录中,这些文件似乎有干扰。 Finally did a "Clean solution", closed VS, deleted the bin and obj folder.最后做了一个“干净的解决方案”,关闭VS,删除bin和obj文件夹。 Restarted VS and rebuild project and the error went away.重新启动 VS 并重建项目,错误消失了。

What kind of HTTP request are you making?你在做什么类型的 HTTP 请求?

This is a slightly left-field answer but have you tried removing the IIS default error page for 404 to check what your API is actually returning?这是一个稍微偏左的答案,但您是否尝试删除 404 的 IIS 默认错误页面以检查您的 API 实际返回的内容?

I had an issue whereby I wanted a controller method to return a 404 when I POSTed the wrong id to it.我有一个问题,我希望控制器方法在我向其发布错误的 ID 时返回 404。 I found that I was always getting the IIS 404 "File or directory not found" page rather than the HTTP response from my API.我发现我总是从我的 API 获得 IIS 404“找不到文件或目录”页面,而不是 HTTP 响应。 Removing the default 404 error page resolved the problem.删除默认的 404 错误页面解决了问题。

Different issue but you never know it may help ;)不同的问题,但你永远不知道它可能有帮助;)

确保未选择解决方案->项目->右键单击属性->应用程序->自动生成绑定重定向

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM