Asp.net web api 简单ASP.NET WebApi参数绑定不起作用

Asp.net web api 简单ASP.NET WebApi参数绑定不起作用,asp.net-web-api,Asp.net Web Api,我不明白为什么这在我的开发服务器(使用IIS Express)上有效,而在生产服务器(Win2K8 R2+IIS 7.5)上无效 我有一个非常简单的WebAPI控制器方法: public HttpResponseMessage Get(string notificationType = "all", int skip=0, int take=25) { Trace.WriteLine(String.Format("Hello, world! From NotifcationsC

我不明白为什么这在我的开发服务器(使用IIS Express)上有效,而在生产服务器(Win2K8 R2+IIS 7.5)上无效

我有一个非常简单的WebAPI控制器方法:

 public HttpResponseMessage Get(string notificationType = "all", int skip=0, int take=25) {
        Trace.WriteLine(String.Format("Hello, world! From NotifcationsController#Get notificationType={0} skip={1} take={2}", notificationType, skip, take));   
        Trace.WriteLine(String.Format("And furthermore, HttpContext.Current.Request[notificationType]={0}", HttpContext.Current.Request["notificationType"]));
        Trace.WriteLine(String.Format("And finally, HttpContext.Current.Request.QueryString[notificationType]={0}", HttpContext.Current.Request.QueryString["notificationType"]));
      ...
 }
在开发服务器上的
http://localhost:1398/api/notifications?notificationType=comments
,一切正常。我在trace.axd中看到了这一点:

 Trace Information
 Category   Message From First(s)   From Last(s)
 Hello, world! From NotifcationsController#Get notificationType=comments skip=0 take=25     
 And furthermore, HttpContext.Current.Request[notificationType]=comments
 And finally, HttpContext.Current.Request.QueryString[notificationType]=comments
 Trace Information
 Category   Message From First(s)   From Last(s)
 Hello, world! From NotifcationsController#Get notificationType=all skip=0 take=25
 And furthermore, HttpContext.Current.Request[notificationType]=    
 And finally, HttpContext.Current.Request.QueryString[notificationType]=

 ...

 Querystring Collection
 Name   Value
 type   comments
但是当在
http://api.nameofmywebsite.com/api/notifications?type=comments
我在trace.axd中看到了这一点:

 Trace Information
 Category   Message From First(s)   From Last(s)
 Hello, world! From NotifcationsController#Get notificationType=comments skip=0 take=25     
 And furthermore, HttpContext.Current.Request[notificationType]=comments
 And finally, HttpContext.Current.Request.QueryString[notificationType]=comments
 Trace Information
 Category   Message From First(s)   From Last(s)
 Hello, world! From NotifcationsController#Get notificationType=all skip=0 take=25
 And furthermore, HttpContext.Current.Request[notificationType]=    
 And finally, HttpContext.Current.Request.QueryString[notificationType]=

 ...

 Querystring Collection
 Name   Value
 type   comments
这对我来说似乎非常奇怪。根据trace.axd中的内容,它似乎不是一个路由问题。。。它击中了正确的控制器和动作

为什么querystring参数没有映射到生产环境中控制器操作的参数

不管它值多少钱,我在开发和服务器上都使用相同的web.config。我想不出什么配置差异会导致这种差异…

我是个白痴

这不起作用,因为我在生产服务器上点击的是“notifications?type=comments”,而不是“notifications?notificationType=comments”

方法参数名称必须与querystring参数名称匹配,才能进行绑定。我知道,但没有意识到我传入了错误的querystring参数名称!发生的事情是,我在几周前更改了方法参数名,同时忘记了它,并且没有意识到浏览器的自动完成功能为我提供了包含旧参数名的历史匹配