tag:blogger.com,1999:blog-12482141117851607072024-03-13T01:12:51.515-07:00Object Oriented World.NET, C#, XML, Web Services, SQL Server, IIS 6.0, T-SQLUnknownnoreply@blogger.comBlogger1125tag:blogger.com,1999:blog-1248214111785160707.post-48945815727500009622007-01-09T23:50:00.000-08:002008-12-09T23:27:23.036-08:00URL Rewriting Using IIS 6.0 and .NET<div>IIS 6.0 does not support URL Rewriting, directly. But writing your own HttpHandler, you specify meanful URLs for your web application. That feature gives much more information to Search Engines ( especially Google ) about your page.<br /><br />Sample:<br />www.domain.com/[url-info]/[id].[extension]<br /><a href="#">www.domain.com/iis-6-url-rewriting/445.article</a><br /><br />In the scenario, we publish articles from the our pages. And we do not want URLs ( like .../default.aspx?id=445 ).<br /><br /><em><strong>Default.aspx</strong> </em><br /><br /><span style="color:#000099;">public void Page_Load(object sender,System.EventArgs e)<br />{<br />string sId = Request.QueryString("id");<br /><br />//Connect database and Get Data with sID<br />// We just simply write sId on the page<br /><br />Response.Write(sId);<br />}<br /></span><br />and then we implement <strong>IHttpHandlerFactory</strong> interface<br /><br /><span style="color:#ff9900;"><span style="color:#333399;">public class myHandler : IHttpHandlerFactory<br />{<br />...<br /><br /><br />public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated)<br />{<br /><br />int s1 = context.Request.RawUrl.LastIndexOf("/");<br />int s2 = context.Request.RawUrl.LastIndexOf(".");<br /><br />// we find id section of the requested URL ( http://www.domain.com/non-existed-folder/<strong>302</strong>.article )<br />string sID = context.Request.RawUrl.Substring(s1 + 1, s2 - s1 -1);<br /><br /><br />//Then rewrite the URL Path of the context<br />context.RewritePath(context.Request.RawUrl + string.Format("?id={0}", sID));<br /><br /><br />//Call the page which execute the code by using sID<br />return PageParser.GetCompiledPageInstance("~/default.aspx", pathTranslated, context);<br />}<br />}</span><br /></span><br /><br /><br /><strong><em>Web.Config</em></strong><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMURpZzI08WMNpfo0PjV_fHwmfZnfU_lroAXQpc4JU6IzfWM7gCUye4DhVb07t711gIOI9yw4eRRU0gtBESFTjY6JwCfJoTky_u24aWMwYD28Ly09jRs-3eu2_5NYa1kSe79NfMruxv6I/s1600-h/2.JPG"><img id="BLOGGER_PHOTO_ID_5024656320670410626" style="CURSOR: hand" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMURpZzI08WMNpfo0PjV_fHwmfZnfU_lroAXQpc4JU6IzfWM7gCUye4DhVb07t711gIOI9yw4eRRU0gtBESFTjY6JwCfJoTky_u24aWMwYD28Ly09jRs-3eu2_5NYa1kSe79NfMruxv6I/s400/2.JPG" border="0" /></a><br /><br /><strong><em>IIS Settings</em></strong><br />Open properties window of your application. From configuration section, add new extension which is be handled by aspnet_isapi.dll<br /><br /><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZb275l-CdEsGZIEJggUQzzsrMTM7eJizXerIkKj7JmkYupYNJBtug11HhHbHjQVVmpth0v-00wbm51HiBJdXfrcsMSgvzh4bV5EMHQJE4FK508b91JjnFXE14zH6ZnO_rj29IN-RiJvc/s1600-h/1.JPG"><img id="BLOGGER_PHOTO_ID_5024650659903514466" style="WIDTH: 167px; CURSOR: hand; HEIGHT: 81px" height="111" alt="" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZb275l-CdEsGZIEJggUQzzsrMTM7eJizXerIkKj7JmkYupYNJBtug11HhHbHjQVVmpth0v-00wbm51HiBJdXfrcsMSgvzh4bV5EMHQJE4FK508b91JjnFXE14zH6ZnO_rj29IN-RiJvc/s200/1.JPG" width="142" border="0" /></a><br /><br /><a href="http://www25.brinkster.com/hayabusa1100/urlrewrite.rar">download the source</a></div>Unknownnoreply@blogger.com0