R
Roshawn
Hi,
I've been fighting tooth and nail trying to handle clunky viewstate data. I happened to
find some code that moves this data to the bottom of the page (to enhance spidering, of
course). Here it is:
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim stringWriter As New System.IO.StringWriter()
Dim htmlWriter As New HtmlTextWriter(stringWriter)
MyBase.Render(htmlWriter)
Dim html As String = stringWriter.ToString()
Dim StartPoint As Integer = _
html.IndexOf("<input type=""hidden"" name=""__VIEWSTATE""")
If StartPoint >= 0 Then
Dim EndPoint As Integer = html.IndexOf("/>", StartPoint) + 2
Dim viewstateInput As String = _
html.Substring(StartPoint, EndPoint - StartPoint)
html = html.Remove(StartPoint, EndPoint - StartPoint)
Dim FormEndStart As Integer = html.IndexOf("</form>") - 1
If FormEndStart >= 0 Then
html = html.Insert(FormEndStart, viewstateInput) '
End If
End If
writer.Write(html)
End Sub 'Render
The thing is, my site's up and running already with about a 25 pages. it would be pretty
inconvenient to add this code to each page in my site. I've heard that an HttpModule or
an HttpHandler is great for this sort of thing, but I don't know how to implement either.
Could anyone "show" me how to go about placing this code in either a module or a handler?
Thanks,
Roshawn
I've been fighting tooth and nail trying to handle clunky viewstate data. I happened to
find some code that moves this data to the bottom of the page (to enhance spidering, of
course). Here it is:
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim stringWriter As New System.IO.StringWriter()
Dim htmlWriter As New HtmlTextWriter(stringWriter)
MyBase.Render(htmlWriter)
Dim html As String = stringWriter.ToString()
Dim StartPoint As Integer = _
html.IndexOf("<input type=""hidden"" name=""__VIEWSTATE""")
If StartPoint >= 0 Then
Dim EndPoint As Integer = html.IndexOf("/>", StartPoint) + 2
Dim viewstateInput As String = _
html.Substring(StartPoint, EndPoint - StartPoint)
html = html.Remove(StartPoint, EndPoint - StartPoint)
Dim FormEndStart As Integer = html.IndexOf("</form>") - 1
If FormEndStart >= 0 Then
html = html.Insert(FormEndStart, viewstateInput) '
End If
End If
writer.Write(html)
End Sub 'Render
The thing is, my site's up and running already with about a 25 pages. it would be pretty
inconvenient to add this code to each page in my site. I've heard that an HttpModule or
an HttpHandler is great for this sort of thing, but I don't know how to implement either.
Could anyone "show" me how to go about placing this code in either a module or a handler?
Thanks,
Roshawn