SiteMorse and VIEWSTATE Fix
SiteMorse is an automated testing and benchmarking tool for many many websites and organisations. My previous employers at RCT were assessed by SiteMorse along with all other Local Authorities in the UK. Despite our best efforts to write super clean XHTML code we could not get over an issue detected by SiteMorse with ASP.net pages that were used for add-on applications to our CMS. As a result of this we were struggling with our SiteMorse ranking. This was a known issue at SiteMorse who had obviously had people approach them about this as there was a knowledge base article about it with no apparent solution.
However, I don’t like to give up that easily so I wrote a little work around which seemed to fix the problem.
In the spirit of wanting to help my fellow workers around the UK I decided to contact SiteMorse about this. Their techy people checked it out and shortly afterwards SiteMorse wrote a news article about it on their site.
The code is as follows. It can be applied either to a Master Page or in individual pages.
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim myMemoryStream As New System.IO.MemoryStream
Dim myStreamWriter As New System.IO.StreamWriter(myMemoryStream)
Dim myWriter As New System.Web.UI.HtmlTextWriter(myStreamWriter)
MyBase.Render(myWriter)
myWriter.Flush()
myWriter.Dispose()
Dim myStreamReader As New System.IO.StreamReader(myMemoryStream)
myStreamReader.BaseStream.Position = 0
Dim pageContent As String = myStreamReader.ReadToEnd
myStreamReader.Dispose()
myMemoryStream.Dispose()
' __EVENTTARGET
Try
pageContent = pageContent.Replace("id=""__EVENTTARGET""", "id=""EVENTTARGET""")
Catch ex As Exception
End Try
' __EVENTARGUMENT
Try
pageContent = pageContent.Replace("id=""__EVENTARGUMENT""", "id=""EVENTARGUMENT""")
Catch ex As Exception
End Try
' __LASTFOCUS
Try
pageContent = pageContent.Replace("id=""__LASTFOCUS""", "id=""LASTFOCUS""")
Catch ex As Exception
End Try
' __VIEWSTATE
Try
pageContent = pageContent.Replace("id=""__VIEWSTATE""", "id=""VIEWSTATE""")
Catch ex As Exception
End Try
' __VIEWSTATEENCRYPTED
Try
pageContent = pageContent.Replace("id=""__VIEWSTATEENCRYPTED""", "id=""VIEWSTATEENCRYPTED""")
Catch ex As Exception
End Try
' __EVENTVALIDATION
Try
pageContent = pageContent.Replace("id=""__EVENTVALIDATION""", "id=""EVENTVALIDATION""")
Catch ex As Exception
End Try
writer.Write(pageContent)
End Sub








Perfect, thanks