升级到 .NET Framework 4.5 后无法访问 HTTP 请求 [英] Lost access to HTTP Request after upgrade to .NET Framework 4.5
问题描述
我有一个 WCF 服务,它以 HTML 形式接受来自 jqGrid 的 POST 请求并返回 JSON.
I have a WCF service that accepts a POST request from jqGrid in the form of HTML form and returns JSON.
虽然一切都在 .NET 4.0 上,但一切正常.我可以通过 request["fieldName"]
访问服务内的表单字段.一旦我升级到 .NET 4.5,我所有的 request["fieldName"]
现在都是空白的..NET 4.5、WCF 和 HttpContext.Current.Request
是否存在某种已知问题?
While things were on .NET 4.0, all worked fine. I could access form fields inside the service via request["fieldName"]
. Once I upgraded to .NET 4.5, all my request["fieldName"]
are now blank. Is there some kind of known issue with .NET 4.5, WCF and HttpContext.Current.Request
?
这是一个例子:
POST http://{REMOVED}/Grid.svc/Execute HTTP/1.1
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept-Encoding: gzip, deflate
_search=false&nd=1355782305975&rows=15&page=1&sidx=modified&sord=desc&search=&category=all
还有,这里是服务:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class GridAccess
{
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json
)]
public GridResponse Execute()
{
var request = System.Web.HttpContext.Current.Request;
所有对 request["fieldName"]
的引用以前都在 .NET 4.0 下工作,现在升级到 .NET 4.5 后,它们返回 NULL.
All references to request["fieldName"]
worked before under .NET 4.0 and now, after upgrade to .NET 4.5, they return NULLs.
推荐答案
问题的根本原因看起来与帖子中描述的问题相同:Visual Studio 2012 安装破坏了我的 2010 WCF 项目.如果我按照本文中建议的解决方法进行操作,我可以看到您的代码再次开始工作.可以参考 this 博文了解更多信息.
The issue's root cause looks to be the same as the issue described in post : Visual Studio 2012 install broke my 2010 WCF project. I can see your code starts working again if I follow the work around suggested in this post. You can refer to this blog post for more information.
这篇关于升级到 .NET Framework 4.5 后无法访问 HTTP 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!