【发布时间】:2016-08-18 21:04:32
【问题描述】:
环境:
Windows 2008 R2 Server
IIS 7.5
ASP.Net 4.5.1
web.config <httpRuntime requestValidationMode="2.0" />
我有一个函数用于从查询字符串、表单或 cookie 集合中返回一个整数 ID。 99% 的时间它都可以正常工作,下面是正在使用的代码:
Function get_id() as Integer
Const k_fld_name as String = "id"
Dim ok As Boolean
Dim id as Integer
Dim fld_val As String
Dim cookie as HttpCookie
Dim req As System.Web.HttpRequest
' Attempt to get ID ...
id = 0
fld_val = Nothing
' Get current request (if any) ...
' NOTE: https://msdn.microsoft.com/en-us/library/system.web.httpcontext.request(v=vs.110).aspx
' ASP.NET will throw an exception if you try to use this property when the HttpRequest object
' Is Not available. For example, this would be true in the Application_Start method of the Global.asax file,
' Or in a method that Is called from the Application_Start method. At that time no HTTP request
' has been created yet ...
Try
req = System.Web.HttpContext.Current.Request
Catch
req = Nothing
End Try
If ( req Is Nothing ) Then
Return id
End If
Try
' Check in querystring ...
fld_val = req.Unvalidated.QueryString( k_fld_name )
' If not found, check in form ...
If ( String.IsNullOrEmpty( fld_val ) ) Then
fld_val = req.Unvalidated.Form( k_fld_name )
' If not found, check in cookie ...
If ( String.IsNullOrEmpty( fld_val ) ) Then
cookie = req.Unvalidated.Cookies( k_fld_name )
If ( cookie isNot Nothing ) Then
fld_val = cookie.Value
End If
End If
End If
Catch ex As Exception
error_log( ex.ToString() )
End Try
[ other logic to convert to Integer ]
Return id
End Function
但每隔一段时间,就会记录以下异常:
System.Web.HttpException (0x80004005): An error occurred while communicating with the remote host. The error code is 0x800703E3. ---> System.NotSupportedException: Specified method is not supported.
at System.Web.HttpResponseStream.get_Position()
at System.Drawing.UnsafeNativeMethods.ComStreamFromDataStream.Seek(Int64 offset, Int32 origin)
at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)
at System.Web.Hosting.IIS7WorkerRequest.ReadEntityCoreSync(Byte[] buffer, Int32 offset, Int32 size)
at System.Web.Hosting.IIS7WorkerRequest.ReadEntityBody(Byte[] buffer, Int32 size)
at System.Web.HttpRequest.GetEntireRawContent()
at System.Web.HttpRequest.FillInFormCollection()
at System.Web.HttpRequest.EnsureForm()
at System.Web.UnvalidatedRequestValues.get_Form()
System.Drawing 出现的原因完全超出了我的理解。我想知道异常消息不支持什么方法?
我是否需要检查 .Unvalidated 属性是否不为 null 以及任何其他集合,即:
If ( req.Unvalidated isNot Nothing ) Then
...
If ( req.Unvalidated.Form isNot Nothing ) Then
...
End If
End If
不幸的是,MS 文档没有说明上述属性是否始终存在(有值)或不存在(为空)。
任何建议或想法都将不胜感激,因为我在这个问题上是一堵砖墙。
提前致谢。
【问题讨论】: