访问Web API 2中的请求对象

时间:2014-02-07 17:39:03

标签: asp.net-web-api2

我在WebAPI中破坏了ModelBinding错误,我看到主键被发布回服务器,但在Model属性的服务器上,Key始终为空。 我决定进一步检查它,看看请求对象是否能够检索该值,如果是这样我将继续并实现我自己的自定义模型绑定器。但是我知道我遇到了另一个问题,我无法弄清楚如何使用Request Object提取值?

这应该相当简单,但找不到正确的方法?

这是Postinformation,OrgCode_PK是提供问题的属性。

Request URL:http://localhost:1398/api/Org/PutOrg
Request Method:PUT
Status Code:404 Primary Key Not found
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:473
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Cookie:sbOverlayID=52335384; __iswl_localhost:1398=0; __ctxpop=1
Host:localhost:1398
Origin:http://localhost:1398
Referer:http://localhost:1398/main.html
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36
X-Requested-With:XMLHttpRequest
Form Dataview sourceview URL encoded
$inlinecount:allpages
OrgCode_PK:ORG6
OrgHeadCode_FK:ORGH12
Code:CBSE-KHN
Name:khkl modified
Description:jhjkh
Address1:hjkh
Address2:jkhkj
CountryCode_FK: edf
CountryName:abyu
StateCode_FK:klh
StateName:yhu
CityCode_FK:hjkh
CityName:khk
ZIP:67u8
RowStatusCode_FK:NEW
RowStatus:NEW ROW
DateCreated:02-06-2014
DateUpdated:02-06-2014
EffectiveDate:02-11-2014
TerminationDate:05-21-2014
CreatedByUserName:jkhkjhkj
UpdatedByUserName:kjkljlk
RowStatusName:NEW ROW
Response Headersview source
Cache-Control:no-cache
Content-Length:41
Content-Type:text/plain; charset=utf-8
Date:Fri, 07 Feb 2014 17:24:52 GMT
Expires:-1
Pragma:no-cache
Server:Microsoft-IIS/8.0
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
X-SourceFiles:=?UTF-8?B?QzpcUHJvamVjdHNcU01XaXRoQXV0aGVudGljYXRpb25cU000XFNNNFxhcGlcT3JnXFB1dE9yZw==?=

1 个答案:

答案 0 :(得分:0)

自己找到了

var httpContext = (HttpContextWrapper)Request.Properties["MS_HttpContext"];
        var OrgCodePK = httpContext.Request.Form["OrgCode_PK"];