This post originated from an RSS feed registered with .NET Buzz
by Jonathan Crossland.
Original Post: An ASP.NET web root link handler
Feed Title: Jonathan Crossland Weblog
Feed URL: http://www.jonathancrossland.com/syndication.axd
Feed Description: Design, Frameworks, Patterns and Idioms
In order to get a useful, all purpose, all use client-side href link back to root, from anywhere down the web folder structure, and paying attention to IIS6, IIS7, Cassini and other Visual Studio internal web hosting scenarious and of course the odd bug within ASP.NET and your own web site code, I created a handler for ~/.
Here is the html I wanted.
<a href="~/">Some link to root of site</a>
public class RootHandler : IHttpHandler
{
#region IHttpHandler Members
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
string toUrl = context.Request.ApplicationPath;
context.Response.Redirect(toUrl);
context.Response.End();
}
#endregion
}