我很困惑爲什麼在我的開發服務器(使用IIS Express)而不是生產服務器(Win2K8 R2 + IIS 7.5)上工作。簡單的ASP.NET WebApi參數綁定不起作用
我有一個非常簡單的WebAPI控制器的方法:在http://localhost:1398/api/notifications?notificationType=comments
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"]));
...
}
在開發服務器,工作的事情。我看到這個的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
但在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=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中的內容,它確實似乎不是路由問題......它正在實現正確的控制器和操作。
爲什麼查詢字符串參數不能映射到生產環境中控制器操作的參數!?
無論它值什麼,我都在開發和服務器上使用相同的web.config。我想不出什麼配置差異會導致這種差異...