Scott Hanselman

XHTML Validating HttpModule for ASP.NET 2

March 30, '06 Comments [4] Posted in ASP.NET | HttpHandler | HttpModule | Tools
Sponsored By

I just love the ASP.NET pipeline. It's so flexible. There's such power to be had when using HttpModules and HttpHandlers together. Here's a good example:

Josh Twist over at JoyOfCode has a "Validator Module" that sits at the very end of the HttpRequest and validates the page you just rendered as XHTML or not, then displays the detailed results. If you've ever found it a hassle to run XHTML validation on your site at runtime you should take a look at this clever idea. With tools like this ValidatorModule plus validation within Visual Studio.NET always improving as well as tools inside of FireFox to validate, there's fewer and fewer excuses to not render XHTML.

Try it out on Josh's site, pound on his demo, and leave him some feedback. You can add it to your .NET 2.0 applications without recompiling. He's also expressed that he could backport it to .NET 1.1 if there's demand.

Sigh, one day my site will be XHTML...until then, consider me transitional. Now, the real question, is it better to look good (render correctly) or feel good (be XHTML)?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

INETA ASP.NET Canada Roadshow

February 22, '06 Comments [4] Posted in ASP.NET | DasBlog | Internationalization | Speaking | HttpHandler | HttpModule | Web Services
Sponsored By

I'll be speaking in Vancouver, BC on March 6th, 2006 at .NET BC and in Victoria at the Victoria .NET Developers Group on March 7th, 2006. Both talks are about DasBlog, working on an Open Source application and what code you can steal/borrow from it. Two cities in a row qualifies as a Poor man's Canada Roadshow in my book.

"Scott Hanselman heads the DasBlog Open Source project along with Omar Shahine, following in the footsteps of Clemens Vasters and his dramatic modification of the BlogX engine. DasBlog is now on version 1.8 and is arguably the most successful ASP.NET blogging engine for the single user. DasBlog is now the work of many folks over many years and while it has some very hairy sections of code, it's full of design techniques and reusable components that you can use in your work today.

Topics Covered:

  • Httpmodules
  • Httphandlers
  • Background threads
  • Internationalization
  • Caching
  • Skinning
  • Creating a macro language
  • Web Services that are more than just SOAP
  • More architectural and design concepts that work in any ASP.NET application"

It should be fun. It'll just be me, but Omar will get mad props even though he won't be there. Omar and I have gone through two DasBlog releases together, first the big performance 1.7 release, then the follow-up 1.8 tightening. Currently 1.9 is in the hopper and will be the last .NET 1.x release as we work on a not-so-super-secret DasBlog.Next project. Currently the checked-in source is very much ahead of the 1.8 release with features like Pluggable Rich Editors with FCK and FTB support, Multi-Author/Single-Blog, Custom Plugin Macros, coComment support, and a much-improved commenting workflow.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Caching in ASP.NET - VaryByParam may need VaryByHeader

November 5, '05 Comments [5] Posted in ASP.NET | DasBlog | HttpModule
Sponsored By

I was tidying up the blog this evening and adding a Reviews category when I visited one of my own pages and noticed that chunks of content were in German. I literally did a double take.

Then I realized that one of my performance optimizations since the site's been getting slammed was to add this to Permalink.aspx (the page that ultimately services DasBlog's single-post pages, no matter what you see in the URL.)

<%@ OutputCache Duration="1800" VaryByParam="*"%>

What could be wrong with that you ask? The idea was to handle different combinations of input and cache page output as appropriate. However, what input would cause my site to serve me, an anglophone, German?

Well, if a German fellow browsing with his browser's Accept-Language header set to anything like "de-DE" and he happened to be the FIRST guy to visit a specific page before it was cached, given the directive above, the page would be cached as it was shown to him. DasBlog will generate most non-content text in the requested language.

Ah! So I needed to:

<%@ OutputCache Duration="1800" VaryByParam="*" VaryByHeader="Accept-Language" %>

Problem solved.

NOTE: I do use HttpCompression and some folks add Accept-Encoding to the VaryByHeader, but the HttpModule I use adds that programatically so everyone gets what they expect. All this caching DOES add up to memory. If someone visted every page in my site at least once with every possible language value, along with HttpCompression on in their browers, then again with HttpCompression off, my Web Server would have to hold a least numOfPages*2*numOfLanguages cached versions of pages.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Permanent Redirects with HTTP 301

October 20, '05 Comments [5] Posted in ASP.NET | DasBlog | XmlSerializer | HttpModule
Sponsored By

The very latest version of DasBlog uses a 301 Permanent Redirect to send aggregators to my feed's new location at FeedBurner. Because it's a 301, most aggregators automatically update their data with a new location and don't bother asking for the original one again.

Here's how to do a hardcoded 301 redirect within ASP.NET:

response.StatusCode = 301;
response.Status = "301 Moved Permanently";
response.RedirectLocation = "http://www.hanselman.com/blog";
response.End();

You can also do this, which I see a lot while looking at the bathroom wall of code folks call Google Groups:

Response.AddHeader("Location","http://www.hanselman.com/blog");

They pretty much do the same thing, but color me reactionary, I like to use the APIs available just for cleanliness's sake.

Of course this is a redirect, not an URL rewrite. Redirect's go all the way back to the requester and provide a hint on where to go next, while rewrites leave the requested the URL the same and tell the web server that something else was requested.

DasBlog has a lovely rewriting HttpModule that you're welcome to use. Erv Walter extended it and added support for redirecting URLs as well as fixing host names. These things are particularly useful if you do not have direct access to your web server's administrative console.

Fritz Onion, my hero but a man I've never met, also has a great redirecting module that's very elegant and coincidentally uses Craig Andera's "Only Configuration Section Handler You'll Ever Need" which is a fantastically snazzy chunk of code that I just can't seem to get folks here at work to latch onto.

Whichever one of these models you use, or if you write the redirect yourself, remember the "principle of least surprise."

If I type in the URL, I don't care how you get me there, just get me there.

UPDATE: It was asked in email "Whats a [good] way around postback URLs getting f'ed up when rewriting URLs." To answer that, I point you to an oldy, but a goody, a blog post with a clever title that no one really every appreciated, IMHO: "Postbacks for Algernon"

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

DasBlog - Nestings Blog

September 7, '05 Comments [0] Posted in ASP.NET | Movies | DasBlog | HttpModule
Sponsored By

Good info from DasBlonde about running multiple nested blogs using DasBlog:

For all you dasBloggers out there...if you want to have nested blogs like I have here:

www.ucsdxcommunity.com

www.ucsdxcommunity.com/ASPNET

...you have to first configure the subdirectory as an IIS application, then remove the <httpModules> section of the web.config in the nested blog. Modules can only be loaded 1x per appdomain, and the nested blog is loaded into the same appdomain by default.

The funny thing is, the error message tells you that it can't load the module twice, so this is actually pretty obvious, but if you are like me, you may have seen this error and started looking for a “bigger“ problem (I always do that...dunno why) ...therefore I didn't pay attention to the error message 'literally“ at first. [DasBlonde.NET]

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Previous Page Page 2 of 5 in the HttpModule category Next Page

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.