Home  |  Site Map
  ConceptDevelopment.NET
Skip Navigation Links
Home
SearchExpand Search
SilverlightExpand Silverlight
DatabaseExpand Database
ValidationExpand Validation
LocalizationExpand Localization
Fun stuffExpand Fun stuff
  Download now

View the code for Global.asax.cs code that implements the HttpFilterDemo class.


About the code
I've only made minor changes to the example UPPERCASE Filter but you can probably think of plenty of other useful stuff...

 

HttpFilter what? 

Would have expected this Google search for httpfilter+httphandler+difference to have more results...

To learn more about Filters and Handlers, try

but if it starts to seem too complex, download and try our Global.asax code or play with the UPPERCASE Filter sample.

But what does it do? 

An HttpFilter gets to access the response being sent to the browser after all other processing is done. The Filter 'intercepts' the Response Stream so you can alter the final data sent to the user.

The sample code on this page parses the Response Stream to alter the paths of links and images in the HTML -- the idea being to enable multiple language versions of the page, where the links all go to a different path, and the images all contain a language code in their filename (assuming the page itself takes care of translating the text on the page).

Read the code and you'll get the idea. Some other ideas are linked on the right, including this great idea to use an HttpFilter to ensure the page output is XHTML-compliant!


Be Warned! 

Quote:

You may not realize it, but the byte[] being passed into the Write(byte[] buffer, int offset, int count) override has already been encoded into the target text encoding. That's right, it's already UTF-8 with the default ASP.NET install. If you're looking for any kind of token in the output stream, you have to encode the token using the same encoding and search for its byte sequence. You could convert the entire buffer back into a string, but that can create large amount of garbage and negatively impact performance and working set. Be sure to profile your memory usage if you take this route. Additionally, for situations like the Catch22 filter where you're trying to find given words, you have to fully understand the character comparison rules for your target language. In the face of internationalization, it can get rather messy.

Useful links

HttpFilter for standards compliance
An intriguing use of HttpFilter - to ensure the outgoing Html Response is XHTML-compliant, even in your ASPX and/or HTML code isn't!

HttpServerUtility Class
Processing a file line-by-line. Thought it might be useful...

Inserting Common Navigation
Another good use: dumping in the nav from an XML file.

Encoding.GetChars Method
I thought this would be useful for processing the Byte array, but it wasn't really.