【问题标题】:ASP.NET Web Api in Web formsWeb 表单中的 ASP.NET Web Api
【发布时间】:2012-03-21 03:17:34
【问题描述】:

我正在尝试将 WEB 表单中的 asp.net web api 与 Visual Studio 2010 (sp1) 一起使用 我已经完成了这些步骤http://myrandomykien.blogspot.com/2012/02/simplest-web-api-site-with-nuget.html

当我使用 Visual Studio 开发服务器时它可以工作,但是当我使用 iis 7.5 时,我收到错误 HTTP 404.0 - Not Found。

编辑

这是我的 Global-asax

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

这是api类

public class GreetingController : ApiController
{
    public string GetGreeting(string id)
    {
        return String.Format("Hello {0}", id);
    }
}

【问题讨论】:

  • 您能提供更多信息吗?现在没什么可做的。

标签: c# asp.net iis-7.5 asp.net-web-api


【解决方案1】:

您必须确保将无扩展名的请求路由到 ASP.NET,这是默认情况下由您的开发服务器完成的,而不是 IIS。

有几种可能的方法。

首先,您可以在system.webServer 的模块部分添加runAllManagedModulesForAllRequests="true"。有人声称有更好的方法,你可以关注他们:

http://www.britishdeveloper.co.uk/2010/06/dont-use-modules-runallmanagedmodulesfo.html

【讨论】:

  • 如果有人在经典模式下使用 iis,Wiktor 的解决方案不起作用,您必须为 iis 安装 extensionLess 更新。 support.microsoft.com/kb/980368
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-04
  • 1970-01-01
  • 2018-08-08
  • 2020-11-29
  • 2019-08-08
  • 1970-01-01
  • 2018-02-02
相关资源
最近更新 更多