[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Firefox Multiple Write Problem using custom Response Filter - Invalid Viewstate

Posted on 2008-10-03
3
Medium Priority
?
465 Views
Last Modified: 2013-11-07
I implemented a whitespace filter based on the following article: http://www.codeproject.com/KB/aspnet/WhitespaceFilter.aspx. I've discovered a problem with Firefox when the response size requires multiple calls to the Filter's Write method. On the rendered page, Firefox inserts a non-standard character between the two Write() outputs. In particular, this often happens in the middle of the Viewstate variable which causes the dreaded System.Web.HttpException: Invalid_Viewstate error. Here's an excerpt from such a problem viewstate:

VVNQIC_ZsdFw7Nz

except that the "_" between the C and Z is a single character. If I paste it in here directly, it renders as the following: &#0 or what may be an ascii null. In firefox, it appears as the diamond question mark to indicate a bad charset character.

This only happens in Firefox. Can someone explain to me why the null character is being inserted and how to correct for this problem?

Thanks in advance.

From WhitespaceFilter Class:
 
   Public Overrides Sub Write( _
         ByVal MyBuffer() As Byte, _
         ByVal offset As Integer, _
         ByVal count As Integer)
 
      Static bFirstPass As Boolean = True
      Static bHTML As Boolean = True
 
      ' See if Filter is Enabled
      Dim sFilter As Object = HttpRuntime.Cache("AppFilterWhiteSpace")
 
      If sFilter Is Nothing Then
         Dim sSQL As String = _
               "SELECT GR0_Value FROM GenericRef WHERE GR0_Type = 'System' AND GR0_Key = 'FilterWhiteSpace'"
         sFilter = CNull(DBInfo.ExecuteScalar(sSQL), "False")
         HttpRuntime.Cache.Insert("AppFilterWhiteSpace", sFilter, Nothing, _
               DateTime.Now.AddMinutes(15), TimeSpan.Zero)
      End If
 
      Dim data(count) As Byte
      Buffer.BlockCopy(MyBuffer, offset, data, 0, count)
 
      ' Process Filter 
      If sFilter <> "True" Then
         ' Use Output As Is 
         _sink.Write(data, 0, data.GetLength(0))
      Else
         ' Filter Leading Whitespace
 
         ' Don't use ASCII encoding here.  The .NET IDE replaces
         ' some characters, such as ®
         ' with a UTF-8 entity.  If you use ASCII encoding,
         ' you'll get B. instead of the registered
         ' trademark symbol.
         Dim s As String = System.Text.Encoding.UTF8.GetString(data)
 
         If bFirstPass Then
            bFirstPass = False
            bHTML = s.ToUpper.IndexOf("<HTML>") > -1
         End If
 
         If Not bHTML Then
            ' Use Output As Is 
            _sink.Write(data, 0, data.GetLength(0))
         Else
            ' Remove Whitespace
 
            ' Break string into separate lines
            ' - each line will end with prior line's carriage return
            ' - each line will begin with leading whitespace that we want to remove
            Dim aLine() As String = s.Split(vbLf)
 
            For iLine As Integer = 0 To aLine.GetUpperBound(0)
               aLine(iLine) = aLine(iLine).TrimStart()
            Next
 
            ' Rejoin the lines
            s = String.Join(vbLf, aLine)
 
            ' Finally, we spit out what we have done.
            Dim outdata() As Byte = System.Text.Encoding.UTF8.GetBytes(s)
            _sink.Write(outdata, 0, outdata.GetLength(0))
        End If
 
      End If
 
   End Sub
 
From Global.asax.vb
 
    Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
      Response.Filter = New WhitespaceFilter(Response.Filter)
    End Sub

Open in new window

0
Comment
Question by:ZekeLA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
alexpercsi earned 1000 total points
ID: 22669213
Just a stab in the dark:

When calling _sink.Write(outdata, 0, outdata.GetLength(0)), you might actually be getting the length wtih one unit too big, causing an ASCII null to be inserted.

Try

_sink.Write(outdata, 0, outdata.GetLength(0)-1) and see if you are missing any characters or if it solves your problem.

Best Regards,
Alex Percsi.
0
 
LVL 1

Author Comment

by:ZekeLA
ID: 22674109
Thank you Alex. For a stab in the dark, it seems to be the correct solution. I still need to do more testing and won't get to do that for a few days but it certainly looks like you solved my problem. I'll update this thread once I complete the additional testing.
0
 
LVL 1

Author Closing Comment

by:ZekeLA
ID: 31502929
I've tested the solution and plan to move it into Production. Apparently, GetBytes includes a final null character [bytes(nLastChar) is nothing] which is not part of the original string. IE ignores the null but Firefox doesn't. Thanks again.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question