<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Damir's Corner - Development|ASP.NET</title>
    <link>http://www.damirscorner.com/</link>
    <description>Notes from Daily Encounters with Technology</description>
    <language>en-us</language>
    <copyright>Damir Arh, M. Sc.</copyright>
    <lastBuildDate>Sun, 17 Sep 2006 11:33:22 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>damir.arh@gmail.com</managingEditor>
    <webMaster>damir.arh@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=cfa5d15a-e15e-4503-90c3-00f55c2d868d</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,cfa5d15a-e15e-4503-90c3-00f55c2d868d.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,cfa5d15a-e15e-4503-90c3-00f55c2d868d.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=cfa5d15a-e15e-4503-90c3-00f55c2d868d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
ASP.NET offers several ways of mapping nice public URLs to cryptic internal URLs matching
the actual implementation.
</p>
        <p>
The simplest way is to match each public URL to its internal value. You can do this
by either creating dummy pages which do the redirecting or by adding them to the <font face="Courier New"><a href="http://msdn2.microsoft.com/en-us/library/ms228302.aspx">urlMappings</a></font> section
of the <font face="Courier New">web.config</font> file (brought by framework 2.0).
The latter solution is preferable because of simpler maintenance but both of them
have the downside of being completely static (an entry is necessary for each mapped
page).
</p>
        <p>
A better solution is to implement an <font face="Courier New"><a href="http://msdn2.microsoft.com/en-us/library/system.web.ihttphandler.aspx">IHttpHandler</a></font> or <font face="Courier New"><a href="http://msdn2.microsoft.com/en-us/library/system.web.ihttpmodule.aspx">IHttpModule</a></font> and
do the mapping by calling <font face="Courier New"><a href="http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.rewritepath.aspx">HttpContext.RewritePath()</a></font>.
You could also change the requested page by using <font face="Courier New"><a href="http://msdn2.microsoft.com/en-us/library/system.web.httpserverutility.transfer.aspx">Server.Transfer()</a></font> or
maybe even <font face="Courier New"><a href="http://msdn2.microsoft.com/en-us/library/system.web.httpserverutility.transfer.aspx">Response.Redirect()</a></font> but
they have <a href="http://www.developerfusion.co.uk/show/4643/4/">their disadvantages</a> when
used for URL mapping.
</p>
        <p>
To avoid having to recompile your <font face="Courier New">IHttpHandler</font> implementation
every time the mapping logic changes or extends you could configure it through
a custom section in the <font face="Courier New">web.config</font> file. Regular expressions
are a nice tool for defining such mappings as demonstrated by <a href="http://pluralsight.com/blogs/fritz/archive/2004/07/21/1651.aspx">here</a> (also
check the comments) or implemented in <a href="http://sourceforge.net/projects/dasblogce/">dasBlog
sources</a> (check <font face="Courier New">newtelligence.DasBlog.Web.Core.UrlMapperModule</font>).
You could even use <a href="http://www.urlrewriting.net/en/Default.aspx">UrlRewritingNet.UrlRewrite</a> if
you don’t like reinventing the wheel.
</p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=cfa5d15a-e15e-4503-90c3-00f55c2d868d" />
      </body>
      <title>Mapping URLs in ASP.NET</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,cfa5d15a-e15e-4503-90c3-00f55c2d868d.aspx</guid>
      <link>http://www.damirscorner.com/MappingURLsInASPNET.aspx</link>
      <pubDate>Sun, 17 Sep 2006 11:33:22 GMT</pubDate>
      <description>&lt;p&gt;
ASP.NET offers several ways of mapping nice public URLs to cryptic internal URLs matching
the actual implementation.
&lt;/p&gt;
&lt;p&gt;
The simplest way is to match each public URL to its internal value. You can do this
by either creating dummy pages which do the redirecting or by adding them to the &lt;font face="Courier New"&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/ms228302.aspx"&gt;urlMappings&lt;/a&gt;&lt;/font&gt; section
of the &lt;font face="Courier New"&gt;web.config&lt;/font&gt; file (brought by framework 2.0).
The latter solution is preferable because of simpler maintenance but both of them
have the downside of being completely static (an entry is necessary for each mapped
page).
&lt;/p&gt;
&lt;p&gt;
A better solution is to implement an &lt;font face="Courier New"&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.ihttphandler.aspx"&gt;IHttpHandler&lt;/a&gt;&lt;/font&gt; or &lt;font face="Courier New"&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.ihttpmodule.aspx"&gt;IHttpModule&lt;/a&gt;&lt;/font&gt; and
do the mapping&amp;nbsp;by calling &lt;font face="Courier New"&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httpcontext.rewritepath.aspx"&gt;HttpContext.RewritePath()&lt;/a&gt;&lt;/font&gt;.
You could also change the requested page by using &lt;font face="Courier New"&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httpserverutility.transfer.aspx"&gt;Server.Transfer()&lt;/a&gt;&lt;/font&gt; or
maybe even &lt;font face="Courier New"&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.httpserverutility.transfer.aspx"&gt;Response.Redirect()&lt;/a&gt;&lt;/font&gt; but
they have &lt;a href="http://www.developerfusion.co.uk/show/4643/4/"&gt;their disadvantages&lt;/a&gt; when
used for URL mapping.
&lt;/p&gt;
&lt;p&gt;
To avoid having to recompile your &lt;font face="Courier New"&gt;IHttpHandler&lt;/font&gt; implementation
every time the mapping logic changes or extends&amp;nbsp;you could configure it through
a custom section in the &lt;font face="Courier New"&gt;web.config&lt;/font&gt; file. Regular expressions
are a nice tool for defining such mappings as demonstrated&amp;nbsp;by &lt;a href="http://pluralsight.com/blogs/fritz/archive/2004/07/21/1651.aspx"&gt;here&lt;/a&gt;&amp;nbsp;(also
check the comments) or implemented in &lt;a href="http://sourceforge.net/projects/dasblogce/"&gt;dasBlog
sources&lt;/a&gt;&amp;nbsp;(check &lt;font face="Courier New"&gt;newtelligence.DasBlog.Web.Core.UrlMapperModule&lt;/font&gt;).
You could even use &lt;a href="http://www.urlrewriting.net/en/Default.aspx"&gt;UrlRewritingNet.UrlRewrite&lt;/a&gt; if
you don’t like reinventing the wheel.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=cfa5d15a-e15e-4503-90c3-00f55c2d868d" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,cfa5d15a-e15e-4503-90c3-00f55c2d868d.aspx</comments>
      <category>Development</category>
      <category>Development/ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=eb6a111b-2b18-47f7-9ffa-30ec0432b4ca</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,eb6a111b-2b18-47f7-9ffa-30ec0432b4ca.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,eb6a111b-2b18-47f7-9ffa-30ec0432b4ca.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=eb6a111b-2b18-47f7-9ffa-30ec0432b4ca</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Be careful when hosting your web site based on DasBlog from a Windows XP machine.
While IIS 6 in Windows 2003 prevents the download of files with unknown extensions
by default, the IIS 5.1 in Windows XP allows downloading such files. In the case of
DasBlog all <font face="Courier New">*.blogtemplate</font> files are at risk. There
are a few sites out there where these files can be downloaded. Although this
probably isn’t a big security risk it might be something you want to prevent. Probably
the easiest way to do that is by modifying the <font face="Courier New">web.config</font> file.
You should add the following line at the end of the <font face="Courier New">&lt;httpHandlers&gt;</font> section:
</p>
        <p>
          <font face="Courier New">&lt;add verb="*" path="*.snippet" type="System.Web.HttpForbiddenHandler"
/&gt;</font>
        </p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=eb6a111b-2b18-47f7-9ffa-30ec0432b4ca" />
      </body>
      <title>Downloading template files from web server</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,eb6a111b-2b18-47f7-9ffa-30ec0432b4ca.aspx</guid>
      <link>http://www.damirscorner.com/DownloadingTemplateFilesFromWebServer.aspx</link>
      <pubDate>Sat, 10 Jun 2006 21:56:44 GMT</pubDate>
      <description>&lt;p&gt;
Be careful when hosting your web site based on DasBlog from a Windows XP machine.
While IIS 6 in Windows 2003 prevents the download of files with unknown extensions
by default, the IIS 5.1 in Windows XP allows downloading such files. In the case of
DasBlog all &lt;font face="Courier New"&gt;*.blogtemplate&lt;/font&gt; files are at risk. There
are a few sites out there where these files can be downloaded. Although&amp;nbsp;this
probably isn’t a big security risk it might be something you want to prevent. Probably
the easiest way to do that is by modifying the &lt;font face="Courier New"&gt;web.config&lt;/font&gt; file.
You should add the following line at the end of the &lt;font face="Courier New"&gt;&amp;lt;httpHandlers&amp;gt;&lt;/font&gt; section:
&lt;/p&gt;
&lt;p&gt;
&lt;font face="Courier New"&gt;&amp;lt;add verb="*" path="*.snippet" type="System.Web.HttpForbiddenHandler"
/&amp;gt;&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=eb6a111b-2b18-47f7-9ffa-30ec0432b4ca" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,eb6a111b-2b18-47f7-9ffa-30ec0432b4ca.aspx</comments>
      <category>Development</category>
      <category>Development/ASP.NET</category>
      <category>Software</category>
      <category>Software/Windows</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=a716fef6-1b21-4e37-8083-67ce4088ed3d</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,a716fef6-1b21-4e37-8083-67ce4088ed3d.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,a716fef6-1b21-4e37-8083-67ce4088ed3d.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=a716fef6-1b21-4e37-8083-67ce4088ed3d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <a href="http://sourceforge.net/projects/dasblogce">DasBlog</a> –
the weblog engine this site is running on – allows extensibility through macros. You’ll
need to use them as soon as you want any additional dynamic content on your site.
(The ads you can see at the bottom of the right side bar are an example of a macro
which I’ve recently updated to make the ad selection a little more advanced.) The <a href="http://www.dasblog.info/">documentation</a> doesn’t
mention their development at all therefore <a href="http://www.vasanth.in/2006/02/01/CreatingMacrosForDasBlog.aspx">the
following post by Vasanth Dharmaraj</a> is probably the best source of information
available on it. It actually discusses everything you need to know to get going. Make
sure you read it before trying to write your first macro.<br /><img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=a716fef6-1b21-4e37-8083-67ce4088ed3d" /></body>
      <title>DasBlog macro development</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,a716fef6-1b21-4e37-8083-67ce4088ed3d.aspx</guid>
      <link>http://www.damirscorner.com/DasBlogMacroDevelopment.aspx</link>
      <pubDate>Sat, 10 Jun 2006 21:42:10 GMT</pubDate>
      <description>&lt;a href="http://sourceforge.net/projects/dasblogce"&gt;DasBlog&lt;/a&gt; – the weblog engine
this site is running on – allows extensibility through macros. You’ll need to use
them as soon as you want any additional dynamic content on your site. (The ads you
can see at the bottom of the right side bar are an example of a macro which I’ve recently
updated to make the ad selection a little more advanced.) The &lt;a href="http://www.dasblog.info/"&gt;documentation&lt;/a&gt; doesn’t
mention their development at all therefore &lt;a href="http://www.vasanth.in/2006/02/01/CreatingMacrosForDasBlog.aspx"&gt;the
following post by Vasanth Dharmaraj&lt;/a&gt; is probably the best source of information
available on it. It actually discusses everything you need to know to get going. Make
sure you read it before trying to write your first macro.&lt;br&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=a716fef6-1b21-4e37-8083-67ce4088ed3d" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,a716fef6-1b21-4e37-8083-67ce4088ed3d.aspx</comments>
      <category>Development</category>
      <category>Development/ASP.NET</category>
      <category>Software</category>
      <category>Software/DasBlog</category>
    </item>
    <item>
      <trackback:ping>http://www.damirscorner.com/Trackback.aspx?guid=5802dda4-53d2-4b1d-ac6d-6a757eb63084</trackback:ping>
      <pingback:server>http://www.damirscorner.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.damirscorner.com/PermaLink,guid,5802dda4-53d2-4b1d-ac6d-6a757eb63084.aspx</pingback:target>
      <dc:creator>Damir Arh</dc:creator>
      <wfw:comment>http://www.damirscorner.com/CommentView,guid,5802dda4-53d2-4b1d-ac6d-6a757eb63084.aspx</wfw:comment>
      <wfw:commentRss>http://www.damirscorner.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5802dda4-53d2-4b1d-ac6d-6a757eb63084</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The problem is pretty straightforward: the web site redesign causes the structure
to change, thus the old addresses become invalid. Since you don’t want the users to
get the dreaded error 404: Object not found, there are a couple of options available
to you (if you’re using IIS – Internet Information Services, that is).
</p>
        <p>
You could just change the error page to match the style of your web site and inform
the visitor about the now missing page or just make the redirection to your new starting
page. This is a bit unfriendly to the visitors if you kept the old content since they
have to find it themselves. It would certainly be better to redirect them directly
to the new address of the old content. But still it’s not a bad idea to do this. It’s
an easy way to keep the users on your website even when they encounter invalid URLs
by whatever reason. Just open up the Custom Errors tab of the virtual directory or
web site properties and set the desired URL for the error 404. But don’t forget that
you have to enter the complete path starting from the root of the site, for example: <font face="Courier New">"/mydirectory/myurl.html"</font>.
</p>
        <p>
If you want to make a different redirection for each page you could just keep the
old pages but instead of having any actual content they would just make a redirection
to the correct new address. This solution has two problems:
</p>
        <ul>
          <li>
It’s difficult to maintain if you have many pages. 
</li>
          <li>
You’re stuck with the client side redirection, i.e. meta refresh tag.</li>
        </ul>
        <p>
To make the redirection server side you could use the redirect options on the Home
Directory tab of the virtual directory or web site properties. But they have some
serious limitations and tend not to work as expected, even more so because the documentation
doesn’t explain them very well. But there’s no reason to worry, I have a better solution
for you. Setup a special 404 URL on the Custom Errors tab as already suggested. But
this time use an <font face="Courier New">asp</font> or <font face="Courier New">aspx</font> page
for it. The supplied query string (<font face="Courier New">Request.QueryString</font>)
contains the missing URL which you can parse out and use to determine the correct
new address corresponding to it. For a few pages a simple <font face="Courier New">select</font> or <font face="Courier New">switch</font> clause
will do but nothing prevents you from having the mappings stored externally, in a
special file or a database table for example. All that’s left is to make a <font face="Courier New">Response.Redirect</font> to
the new address.
</p>
        <p>
There’s one more thing to take care of. If you moved your site to a new subdirectory
and chose the last suggested solution, don’t forget to setup a similar simple starting
page which just redirects the visitors to the new starting page. Trying to open the
site without this page will namely cause an error 403: Forbidden, because a directory
listing will be attempted which you have (hopefully) prevented.
</p>
        <p>
Thanks go to <a href="http://blog.forret.com/blog/index.html">Peter Forret</a> for
some of the <a href="http://blog.forret.com/blog/2004/04/fancy-redirection-on-iis-5.html">ideas</a> I
used to make this work when redesigning my page.<br /></p>
        <img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=5802dda4-53d2-4b1d-ac6d-6a757eb63084" />
      </body>
      <title>Redirecting web pages to specific addresses</title>
      <guid isPermaLink="false">http://www.damirscorner.com/PermaLink,guid,5802dda4-53d2-4b1d-ac6d-6a757eb63084.aspx</guid>
      <link>http://www.damirscorner.com/RedirectingWebPagesToSpecificAddresses.aspx</link>
      <pubDate>Thu, 19 Jan 2006 22:35:50 GMT</pubDate>
      <description>&lt;p&gt;
The problem is pretty straightforward: the web site redesign causes the structure
to change, thus the old addresses become invalid. Since you don’t want the users to
get the dreaded error 404: Object not found, there are a couple of options available
to you (if you’re using IIS – Internet Information Services, that is).
&lt;/p&gt;
&lt;p&gt;
You could just change the error page to match the style of your web site and inform
the visitor about the now missing page or just make the redirection to your new starting
page. This is a bit unfriendly to the visitors if you kept the old content since they
have to find it themselves. It would certainly be better to redirect them directly
to the new address of the old content. But still it’s not a bad idea to do this. It’s
an easy way to keep the users on your website even when they encounter invalid URLs
by whatever reason. Just open up the Custom Errors tab of the virtual directory or
web site properties and set the desired URL for the error 404. But don’t forget that
you have to enter the complete path starting from the root of the site, for example: &lt;font face="Courier New"&gt;"/mydirectory/myurl.html"&lt;/font&gt;.
&lt;/p&gt;
&lt;p&gt;
If you want to make a different redirection for each page you could just keep the
old pages but instead of having any actual content they would just make a redirection
to the correct new address. This solution has two problems:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
It’s difficult to maintain if you have many pages. 
&lt;/li&gt;
&lt;li&gt;
You’re stuck with the client side redirection, i.e. meta refresh tag.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
To make the redirection server side you could use the redirect options on the Home
Directory tab of the virtual directory or web site properties. But they have some
serious limitations and tend not to work as expected, even more so because the documentation
doesn’t explain them very well. But there’s no reason to worry, I have a better solution
for you. Setup a special 404 URL on the Custom Errors tab as already suggested. But
this time use an &lt;font face="Courier New"&gt;asp&lt;/font&gt; or &lt;font face="Courier New"&gt;aspx&lt;/font&gt; page
for it. The supplied query string (&lt;font face="Courier New"&gt;Request.QueryString&lt;/font&gt;)
contains the missing URL which you can parse out and use to determine the correct
new address corresponding to it. For a few pages a simple &lt;font face="Courier New"&gt;select&lt;/font&gt; or &lt;font face="Courier New"&gt;switch&lt;/font&gt; clause
will do but nothing prevents you from having the mappings stored externally, in a
special file or a database table for example. All that’s left is to make a &lt;font face="Courier New"&gt;Response.Redirect&lt;/font&gt; to
the new address.
&lt;/p&gt;
&lt;p&gt;
There’s one more thing to take care of. If you moved your site to a new subdirectory
and chose the last suggested solution, don’t forget to setup a similar simple starting
page which just redirects the visitors to the new starting page. Trying to open the
site without this page will namely cause an error 403: Forbidden, because a directory
listing will be attempted which you have (hopefully) prevented.
&lt;/p&gt;
&lt;p&gt;
Thanks go to &lt;a href="http://blog.forret.com/blog/index.html"&gt;Peter Forret&lt;/a&gt; for
some of the &lt;a href="http://blog.forret.com/blog/2004/04/fancy-redirection-on-iis-5.html"&gt;ideas&lt;/a&gt; I
used to make this work when redesigning my page.&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.damirscorner.com/aggbug.ashx?id=5802dda4-53d2-4b1d-ac6d-6a757eb63084" /&gt;</description>
      <comments>http://www.damirscorner.com/CommentView,guid,5802dda4-53d2-4b1d-ac6d-6a757eb63084.aspx</comments>
      <category>Development</category>
      <category>Development/ASP.NET</category>
      <category>Software</category>
      <category>Software/Windows</category>
    </item>
  </channel>
</rss>