Not a User Error: Moving my DasBlog directory

If your rss feed reader just went crazy over my site, I apologize.  I recently moved my blog from the application root to a subdirectory in order to allow other .NET applications to run properly in other subdirectories.

In order to make the imaginativeuniversal site still work with searches that expect to find content at the old location, I had to create an HttpHandler to redirect page requests to the “/blog” subdirectory, including requests for the rss feed.  This had some unintended results, such as republishing all the old rss entries.

This was a migration of a DasBlog application to another directory.  Should anyone be interested, this is how I wrote the HttpHandler CategoryHandler to redirect all requests to the root to my “/blog” subdirectory:

using System;

using System.Web;

using System.Web.UI;

 

namespace IUHandlers

{

    public class CategoryHandler : IHttpHandler

    {

 

        public bool IsReusable

        {

            get { return true; }

        }

 

        public void ProcessRequest(HttpContext context)

        {

            string path = context.Request.Path;

            string syndicationPath = “/SyndicationService.asmx”;

            if (path.IndexOf(“/blog”) == -1)

            {

 

                int lastSlash = path.LastIndexOf(‘/’);

                string pre = path.Substring(0, lastSlash);

                string post = path.Substring(lastSlash);

                if (path.IndexOf(syndicationPath

                    ,StringComparison.CurrentCultureIgnoreCase) > -1)

                {

                    post = syndicationPath + post;

                }

                context.Response.Redirect(“~/blog” + post);

            }

        }

    }

}

I compiled my handler and placed it in the bin folder at the root of my site.  I then added a web.config file to the root with this setting:

<httpHandlers>

      <add verb=GET path=*.asmx type=IUHandlers.CategoryHandler, IUHandlers/>

      <add verb=GET path=*.aspx type=IUHandlers.CategoryHandler, IUHandlers/>

This allows me to run other ASP.NET applications beneath the root directory of my site as long as I remember to add the following two settings to each of their web.config files:

    <httpHandlers>

      <remove verb=GET path=*.asmx/>

      <remove verb=GET path=*.aspx/>

I’m not sure if it’s the most elegant solution, but it seemed to do the job.

2 thoughts on “Not a User Error: Moving my DasBlog directory

  1. I have run across other posts and remarks which are loosely in accord with Not a User Error: Moving my DasBlog directory but I have to recognise that this post has some extra information. See that you do not encumber yourself. Multiple authors restrain themselves to subjects they believe they are able to manage. Be confident you can go as far as your psyche will allow you.

  2. Hi, Thanks for sharing such a wonderful piece of information. I must say that while reading your post I found my thoughts in agreement with the topic that you have discussed, which happens very rare.

Comments are closed.