2013-05-06 50 views
5

我的網站每天都拋出以下例外,我找不到解決方案。 我在網上做了很少的研究,這是我到目前爲止做的。向aspx添加下面的選項不會解決問題。System.Web.UI.ViewStateException,無效的視圖狀態

ValidateRequest = 「假」 EnableEventValidation = 「假」 ViewStateEncryptionMode = 「從不」 EnableViewStateMac = 「假」

而且,我的推薦鏈接的網址正確,我不知道它是如何重定向有兩個(相同)參數。我的推介頁面中沒有這樣的鏈接。請幫忙。

錯誤日誌

URL : http://www.abcd.com/company-details.aspx?com=asia-pacific-pte-ltd&com=asia-pacific-pte-ltd 

referral URL : http://www.abcd.com/companies/asia-pacific-pte-ltd/ 

Inner Exception Type: System.Web.UI.ViewStateException 

Inner Exception: Invalid viewstate. Client IP: 192.162.19.193 Port: 1966 User-Agent: Opera/9.80 (Windows NT 6.1; WOW64; MRA 6.0 (build 6001)) Presto/2.12.388 Version/12.11 ViewState: /wEPDwULLTEyMTAyMTY3NDAPZBYCAgMPZBYOZg8QDxYGHg1EYXRhVGV4dEZpZWxkBQdDb3VudHJ5Hg5EYXRhVmFsdWVGaWVsZAUNQ2xlYW5fQ291bnRyeR4LXyFEYXRhQm91bmRnZBAVCgNBbGwFQ2hpbmEJSG9uZyBLb25nBUluZGlhCUluZG9uZXNpYQhNYWxheXNpYQtQaGlsaXBwaW5lcwlTaW5nYXBvcmUIVGhhaWxhbmQHVmlldG5hbRUKA0FsbAVjaGluYQlob25nLWtvbmcFaW5kaWEJaW5kb25lc2lhCG1hbGF5c2lhC3BoaWxpcHBpbmVzCXNpbmdhcG9yZQh0aGFpbGFuZAd2aWV0bmFtFCsDCmdnZ2dnZ2dnZ2dkZAIBDxAPFgYfAAUISW5kdXN0cnkfAQUOQ2xlYW5fSW5kdXN0cnkfAmdkEBXFAgNBbGwSQWR2YW5jZWQgTWF0ZXJpYWxzC0FkdmVydGlzaW5nCkFlc3RoZXRpY3MLQWdyaWN1bHR1cmUkQWdyaWN1bHR1cmUgLSBBZ3JpY3VsdHVyYWwgTWFjaGluZXJ5G0FncmljdWx0dXJlICYgRm9vZCBQcm9kdWN0cxBBaXItY29uZGl0aW9uaW5nHUFpci1maWx0cmF0aW9uICYgUHVyaWZpY2F0aW9uB0FpcnBvcnQJQWx1bWluaXVtFEFuYWx5dGljYWwgRXF1aXBtZW50GkFuYWx5dGljYWwgSW5zdHJ1bWVudGF0aW9uFUFuYWx5dGljYWwgVGVjaG5vbG9neRZBbmQgSW50ZXJpb3IgRGVzaWduZXJzEUFuaW1hbCBQcm9kdWN0aW9uCEFudGlib2R5KUFwc... 

Inner Source: 

Exception Type: System.Web.HttpException 

Exception: The state information is invalid for this page and might be corrupted. 

Stack Trace: at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) at System.Web.UI.HiddenFieldPageStatePersister.Load() at System.Web.UI.Page.LoadPageStateFromPersistenceMedium() at System.Web.UI.Page.LoadAllState() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.exhibition_details_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\0f461847\442b0502\App_Web_bfjqxdef.20.cs:line 0 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

UPDATE 我已經通過從下方鏈路 http://www.codeproject.com/Articles/14733/ViewState-Compression

壓縮視圖狀態固定該錯誤並通過更換固定爲一個基地-64字符數組錯誤無效長度與此相關的原始方法。

protected override object LoadPageStateFromPersistenceMedium() 
    { 
     string viewState = Request.Form["__VSTATE"]; 
     viewState = viewState.Replace(" ", "+"); 

     int mod4 = viewState.Length % 4; 
     if (mod4 > 0) 
     { 
      viewState += new string('=', 4 - mod4); 
     } 
     byte[] bytes = Convert.FromBase64String(viewState); 
     bytes = Compressor.Decompress(bytes); 
     LosFormatter formatter = new LosFormatter(); 
     return formatter.Deserialize(Convert.ToBase64String(bytes)); 
    } 

謝謝大家的幫助:)

回答

3

我很抱歉說,但是您的網站並沒有什麼,你需要儘快重新啓用EventValidations。

你看到的是an attempt to hack your site通過發送很多測試numbers with your ViewState trying to find your hash key

The IP you give have a big list of activity the last few days

現在,替代可能導致此錯誤的是ViewState的中斷。如果您的ViewState太大,您可以compress it and split it。您也可以disable all the controls that not needed。你也可以添加一個log to see from inside what's is going on right on a base page

+1

我刪除了這些EnableEventValidation =「false」ViewStateEncryptionMode =「Never」EnableViewStateMac =「false」,並將它從您給我的鏈接中壓縮出來,並解決了問題。非常感謝你:) – bluebird 2013-05-07 09:38:07

+0

雖然我現在收到了這個錯誤,但Base-64字符數組的長度無效。幫助 – bluebird 2013-05-08 01:59:37

+0

@ user597729如果你只在日誌中看到它,請檢查IP,因爲我說你可能是一個黑客嘗試,你不必擔心。如果你看到它作爲用戶...那麼也許它是一個問題。 – Aristos 2013-05-08 06:54:18

0

是它的工作對我來說太

在這裏vbnet

Compressor.vb

Imports System.IO 
Imports System.IO.Compression 
Public Class Compressor 

Public Shared Function Compress(ByVal data() As Byte) As Byte() 
    Dim output As MemoryStream = New MemoryStream 
    Dim gzip As GZipStream = New GZipStream(output, CompressionMode.Compress, True) 
    gzip.Write(data, 0, data.Length) 
    gzip.Close() 
    Return output.ToArray 
End Function 

Public Shared Function Decompress(ByVal data() As Byte) As Byte() 
    Dim input As MemoryStream = New MemoryStream 
    input.Write(data, 0, data.Length) 
    input.Position = 0 
    Dim gzip As GZipStream = New GZipStream(input, CompressionMode.Decompress, True) 
    Dim output As MemoryStream = New MemoryStream 
    Dim buff() As Byte = New Byte((64) - 1) {} 
    Dim read As Integer = -1 
    read = gzip.Read(buff, 0, buff.Length) 

    While (read > 0) 
     output.Write(buff, 0, read) 
     read = gzip.Read(buff, 0, buff.Length) 

    End While 

    gzip.Close() 
    Return output.ToArray 
End Function 
End Class 

,這粘貼裏面的Default.aspx 需要

進口System.IO

Protected Overrides Function LoadPageStateFromPersistenceMedium() As Object 
    Dim viewState As String = Request.Form("__VSTATE") 
    Dim bytes() As Byte = Convert.FromBase64String(viewState) 
    bytes = Compressor.Decompress(bytes) 
    Dim formatter As LosFormatter = New LosFormatter 
    Return formatter.Deserialize(Convert.ToBase64String(bytes)) 
End Function 

Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal viewState As Object) 
    Dim formatter As LosFormatter = New LosFormatter 
    Dim writer As StringWriter = New StringWriter 
    formatter.Serialize(writer, viewState) 
    Dim viewStateString As String = writer.ToString 
    Dim bytes() As Byte = Convert.FromBase64String(viewStateString) 
    bytes = Compressor.Compress(bytes) 
    ClientScript.RegisterHiddenField("__VSTATE", Convert.ToBase64String(bytes)) 
End Sub 
相關問題