Move ViewState with HttpModule or HttpHandler

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
 
G

Guest

Couple of ideas:
1) I really doubt that moving the hidden viewstate field to the "Bottom of
the page" would have much, if any effect on the results of the various spider
bots. They haven't the slightest interest in the gobbledegook contained in
your ViewState field.

2) If your ViewState is really that big, you have 2 options:

a) Chop it down by disabling ViewState for page and / or controls where it
is unnecessary.
b) Don't store ViewState in the page at all. There are several options for
overriding the Load / Save ViewState methods of the Page Class to store it
either in Session, Cache, or even in a Database - all out of the page, on the
server.
Peter
 
R

Roshawn

Hi Peter
2) If your ViewState is really that big, you have 2 options:

a) Chop it down by disabling ViewState for page and / or controls where it
is unnecessary.
b) Don't store ViewState in the page at all. There are several options for
overriding the Load / Save ViewState methods of the Page Class to store it
either in Session, Cache, or even in a Database - all out of the page, on the
server.
Peter

Overriding the Load / Save ViewState methods of the Page class seems like the more logical
solution to my problem. Thanks for the heads up. :)

Have a nice day,
Roshawn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top