Avatar of smacca
smacca
Flag for Australia asked on

Create a HttpModule to place ViewState at bottom of page - sample already provided.

Hi,

I have provided a BasePage OnRender sample that grabs the viewstate and places it at the bottom of the page to improve Search Engine Optimisation.

  http://professionalaspnet.com/archive/2006/07/30/Moving-ViewState-to-Optimize-Web-Pages.aspx

However, I would like to improve my architecture and create a HttpModule that does the work for me.
I have provided code for .NETv1.0 that ensures valid XHTML is output for .NETv1.0 sites (i.e. viewstate must be put within DIV tags and form must use 'id' attribute instead of name). This will provide a great example of how to achieve what I am after.

This code will be great for all .NETv2.+ developers working on web projects.

Any help would be appreciated.

Thanks.
Steve
basepage-render.txt
PageFilter.cs.txt
PageFilterHttpModule.cs.txt
ASP.NETWeb ApplicationsC#

Avatar of undefined
Last Comment
smacca

8/22/2022 - Mon
REA_ANDREW

Have you, or are you aware of the .NET 2.0 Control Adapters?  This allows you to change the output of all the base controls like forms, form controls etc...

Andrew
smacca

ASKER
Have not heard of control adapters but you have my curiosity at a peak.
Will look into this tonight - thanks for the great tip.

Would the adapters be preferable in this case?
I still think HttpModule is best as it grabs the HTML stream and modifies it.
REA_ANDREW

I have been looking into this, and it does not seem that a HttpModule or Handler seem sto be a vlaid approach, simply because you either cannot or are limited to the page output before it is renedered.  This is why overriding the Page Render Method seems to be the best way.

I create a derived Page Class called SEOPage and implemented that render code!  Works a treat.  

I will try and look into it more as I can see where you are going.  My other attempt was to use

Server.Execute(FilePath, TextWriter)  this way I can programatically render a page, change it and spew out the html to the context.  I cannot do this though, as the Server.Execute method fails each time when I hook it up to a aspx request.

Andrew
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
smacca

ASKER
Hi Andrew,

Fantastic you are using the Render code in your basepage. It is really great.
Has potential to give you improved results for Search Engine ranking - as outlined in the referenced material.

Would love to see a HttpModule at work.
I have provided a working sample of a HttpModule I use with my .NETv1.0 sites to output valid XML.
It would be a great starting point for yourself or any other developers.

Am totally confident you would use in all projects, once it was written - one of those, write once use forever bits of code.

Thanks for your great input.
ASKER CERTIFIED SOLUTION
REA_ANDREW

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
smacca

ASKER
Andrew, your a legend - is that a working sample?? Does it work a treat??
Thanks for your time - it is much appreciated.
REA_ANDREW

Yes, I tried here on my local computer, and it works a treat.  I  am glad you asked the question now, as I will be implmenting this on my server to test out!!

:-)

Andrew
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
smacca

ASKER
Is this working fine for your Andrew - I havent used since we discussed as it may have been causing bugs - not completely sure though as project was in start period.