System.Web.UI.ViewStateException ,Invalid viewstate

一笑奈何 提交于 2019-12-04 08:42:25
Aristos

I am sorry that say that but your site did not have anything, and you need to re-enable your EventValidations as soon as possible.

What you see is an attempt to hack your site by sending many test numbers with your ViewState trying to find your hash key.

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

Now, alternative what may cause this error is the breaking of the ViewState. You can compress it and split it if you have too big ViewState. You can also disable all the controls that not needed. Also you can add a log to see from inside what's is going on right on a base page.

yes it works for me too

here in 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

and this you paste inside default.aspx it needs

Imports 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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!