473,473 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Move ViewState with HttpModule or HttpHandler

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
Feb 4 '07 #1
2 2454
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
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Roshawn" wrote:
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
Feb 5 '07 #2
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
Feb 5 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Rilling | last post by:
Can an HttpHandler or HttpModule be invoked on non-ASP.NET pages such as images or ASP or HTML pages? Can I trap a request for those pages? If not, how might I trap those requests?
0
by: Bruce B | last post by:
Hi group, I'm experiencing some extreme weirdness over the last week with IIS related to it's Mappings and how .NET is behaving. I can't explain the behavior as it seems very random. Our...
3
by: MWells | last post by:
I'm having an issue getting my HttpHandlers and HttpModules to play together nicely. My HttpHandlers take special document types (defined by extension) and process them specially. I might have...
0
by: Mike Schilling | last post by:
(I've asked this on the C# newsgroup; I'm hoping someone over here might have an idea.) We have a C# application running under ASP.NET. It wasn't written using any VS.NET magic; all of the call...
0
by: tshad | last post by:
I am trying to get an HttpHandler I found on the Web to work. It is called FreeText. It allows fancy handling of a Textbox. This program is just a dll that you set up as an HttpHandler: ...
1
by: Max | last post by:
I have my HTTPModule or HTTPHandler registered to process all file types (*). I have IIS configured to pass all requests to ASP.NET for this virtual directory. In some cases depending on the...
7
by: Tomasz | last post by:
Hello Developers, I have an interesting problem. How, or when can I access SessionState from HttpModule? It seems that session state is only available when *.aspx page is requested. It is not...
3
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi, I need to write asynchronous HTTPModule which will sometimes execute long job. I've written it using AddOnBeginRequestAsync but it still executes synchronously - I am checking performance...
3
by: Guzeppi | last post by:
if i want to create a redirection service, i.e. requests on a certain url are redirected to other urls depending on the querystring parameters in the request, what is best to use in this case...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.