Tuesday, July 11, 2006

Google Site Maps and Http Handlers Part 2

In my last post I discussed using the method for the section of the web.config file. The remove element comes in handy if you’ve added an HttpHandler to the root of your Web site, but don’t want that handler to be loaded in sites below the root Web site.

Today I found a better way to control inheritance of the Http Handlers. The <add> element for Http Handlers has an attribute, validate, which tells ASP.NET whether it should load the class immediately or wait until a request comes. By default the value is set to true. Setting validate to false prevents the class from being loaded and thus eliminates the error.

In the case of the Google Site Maps handler, we had the following where validate was defaulting to true

<httpHandlers> <add verb="*" path="googlesitemap.axd" type="Newtonsoft.GoogleSitemap.GoogleSitemapHandler, Newtonsoft.GoogleSitemap"/> </httpHandlers>

We can change the add element to this to prevent ASP.NET from loading the googlesitemap.dll until we browse to googlesitemap.axd.

<httpHandlers> <add verb="*" path="googlesitemap.axd" type="Newtonsoft.GoogleSitemap.GoogleSitemapHandler, Newtonsoft.GoogleSitemap" validate="false”/> </httpHandlers>

Of course within your subsites, ASP.NET will generate an error if you try to browse to http://yourdomain.com/subsite/googlesitemap.axd. Ideally I wish there were an attribute like inheritance=false but until then this gets the job done.

No comments: