Sunday, May 11, 2008

Writing SEO friendly url using HttpHandlers in ASP.NET

In general it is recommend to not use querystring in the url as search engines doesn't rank those pages well and give very low priority. To avoid querystring there are several third party component that can be used like ISAPI, url rewriter. However in this article, I am going to show you how to rewrite url using ASP.NET built in HttpHandler.
 
Introduction

HttpHandler is the low level Request and Response API to service incoming Http requests. All handlers implement the IHttpHandler interface. There is no need to use any extra namespace to use it as it contains in the System.Web namespace. Handlers are somewhat analogous to Internet Server Application Programming Interface (ISAPI) extensions.

In this article, I am going to explain how to use HttpHandler to create a SEO friendly as well as user friendly url. During this article I will create two .aspx file, one HandlerUrl.cs class file. I am assuming here that I have to show different article based on the id I get from the request. But I will not get the id as querystring but as part of the name of the page like article1.aspx or article2.aspx. Here 1 and 2 is my article id. I will extract it and send into my page (showarticle.aspx) using Server.Transfer method so that my url in the browser will be like article1.aspx but internally it will be served as showarticle.aspx?id=1.
 

No comments: