2016-08-18 6 views
0

環境:ASP.Net - 検証されていないリクエストの例外?

Windows 2008 R2 Server 
IIS 7.5 
ASP.Net 4.5.1 
web.config <httpRuntime requestValidationMode="2.0" /> 

私はクエリ文字列、フォームまたはクッキーコレクションから整数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プロパティは、ならびに任意の他のコレクションをゼロにされていないかどうかを確認する必要があります:

If (req.Unvalidated isNot Nothing) Then 
    ... 

    If (req.Unvalidated.Form isNot Nothing) Then 

    ... 

    End If 

End If 

残念ながら、MSのドキュメントは、上記のプロパティが常に存在しているか否かの状態はありません(値を持っているか)(nullである)。

私はこの建物のレンガの壁にぶつかっているので、どんな提案やアイデアも高く評価されます。

ありがとうございます。

答えて

0

は、コードファイルで使用

<% ValidateRequest="false"%> 

、あなたのaspxページにValidateRequest="false"を入れ

Request.Unvalidated.Form["yourrequest"]; 
関連する問題