<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Tips &amp; Tricks for ASP.NET, IIS, and Visual Web Developer : URL Rewrite</title><link>http://blogs.msdn.com/webdevelopertips/archive/tags/URL+Rewrite/default.aspx</link><description>Tags: URL Rewrite</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Tip #38: Did you know... How to use Failed Request Tracing to trace Rewrite Rules?</title><link>http://blogs.msdn.com/webdevelopertips/archive/2008/12/28/tip-38-did-you-know-how-to-use-failed-request-tracing-to-trace-rewrite-rules.aspx</link><pubDate>Sun, 28 Dec 2008 22:54:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9255068</guid><dc:creator>WebDevTools</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/webdevelopertips/comments/9255068.aspx</comments><wfw:commentRss>http://blogs.msdn.com/webdevelopertips/commentrss.aspx?PostID=9255068</wfw:commentRss><description>&lt;p&gt;IIS7.0 Failed Request Tracing (FRT) is a powerful troubleshooting tool for request-processing failures. More details regarding FRT and how to enable it can be be found &lt;a href="http://learn.iis.net/page.aspx/266/troubleshooting-failed-requests-using-tracing-in-iis7/" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Once the failed request tracing is enabled for your site, do the following to trace rewrite rules:&lt;/p&gt;  &lt;li&gt;Double click on &amp;quot;Failed Request Tracing Rules&amp;quot; icon to get to the list of FRT rules.&lt;/li&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.HowtouseFailedRequestTracingtotraceR_A70F/frt.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="443" alt="frt" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.HowtouseFailedRequestTracingtotraceR_A70F/frt_thumb.png" width="544" border="0" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;li&gt;Click on &amp;quot;Add ...&amp;quot; action to bring up the FRT rule creation wizard. &lt;/li&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.HowtouseFailedRequestTracingtotraceR_A70F/frt1.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="385" alt="frt1" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.HowtouseFailedRequestTracingtotraceR_A70F/frt1_thumb.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;li&gt;On first page of the wizard choose &amp;#8220;All content (*)&amp;#8221; &lt;/li&gt;  &lt;li&gt;Click &amp;#8220;Next&amp;#8221; and specify the status code(s) as &amp;#8220;200-399&amp;#8221;&lt;/li&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.HowtouseFailedRequestTracingtotraceR_A70F/frt2.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="385" alt="frt2" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.HowtouseFailedRequestTracingtotraceR_A70F/frt2_thumb.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;li&gt;Click Next and then uncheck all the trace providers except &amp;#8220;WWW Server&amp;#8221; and then uncheck all the provider areas except &amp;#8220;Rewrite&amp;#8221;&lt;/li&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.HowtouseFailedRequestTracingtotraceR_A70F/frt3.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="383" alt="frt3" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.HowtouseFailedRequestTracingtotraceR_A70F/frt3_thumb.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;li&gt;Click on Finish to save the FRT rule.&lt;/li&gt;  &lt;p&gt;After the FRT rule is created, the log will start getting generated in %SystemDrive%\inetpub\Logs\FaileReqLogFiles\. You can open this log by using Internet Explorer, and it will be rendered as an HTML document that can be easily browsed.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;PS: &lt;/strong&gt;If the Failed Request Tracing was installed after URL rewrite module, the &amp;quot;Rewrite&amp;quot; area in Trace Providers may not be available. If you do not see &amp;quot;Rewrite&amp;quot; area listed there, go to Add/Remove programs and then run URL rewrite module installer in repair mode.&lt;/p&gt;  &lt;p&gt;For more details on this, read this &lt;a href="http://learn.iis.net/page.aspx/467/using-failed-request-tracing-to-trace-rewrite-rules/" target="_blank"&gt;walkthrough&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Don Raman      &lt;br /&gt;&lt;/strong&gt;SDET, &lt;a href="http://www.iis.net/"&gt;IIS Team&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9255068" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/IIS/default.aspx">IIS</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/URL+Rewrite/default.aspx">URL Rewrite</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/Failed+Request+Tracing/default.aspx">Failed Request Tracing</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/FRT/default.aspx">FRT</category></item><item><title>Tip #36: Did you know... How to manage pilot or beta program for your site using Application Request Routing in IIS7.0?</title><link>http://blogs.msdn.com/webdevelopertips/archive/2008/12/22/tip-36-did-you-know-how-to-manage-pilot-or-beta-program-for-your-site-using-application-request-routing-in-iis7-0.aspx</link><pubDate>Mon, 22 Dec 2008 21:11:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9247655</guid><dc:creator>WebDevTools</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/webdevelopertips/comments/9247655.aspx</comments><wfw:commentRss>http://blogs.msdn.com/webdevelopertips/commentrss.aspx?PostID=9247655</wfw:commentRss><description>&lt;p&gt;Won't it be cool if you can target and route appropriate users of your site to your pilot/beta/new looking site based on user's profile. This may help you in managing select users who have previously signed for pilot program and redirect them to new looking web site and gather feedback. This is a very typical situation when your web site is evolving or going a major change. IIS7.0 Application Request Routing (ARR) module helps you achieve this. The other situation where this can help is to limit and manage the amount of traffic that is routed to pilot site. There can be numerous other scenarios like ones mentioned where ARR can assist but the focus of the tip will be to learn how to get this done through ARR. You can apply it to other related scenario too.&lt;/p&gt;  &lt;p&gt;Let's say for example we would like to redirect all users who have .NET Framework 3.5 installed and are using the browser Internet Explorer to the pilot site. For achieving this using ARR, follow the below steps:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Launch IIS Manager. &lt;/li&gt;    &lt;li&gt;Create a server farm named &amp;quot;&lt;strong&gt;pilotSiteServers&lt;/strong&gt;&amp;quot; using this &lt;a href="http://learn.iis.net/page.aspx/485/define-and-configure-an-application-request-routing-server-farm/" target="_blank"&gt;walkthrough&lt;/a&gt;. This server farm will represent the pilot/beta environment. &lt;/li&gt;    &lt;li&gt;Create another server farm named &amp;quot;&lt;strong&gt;productionSiteServers&lt;/strong&gt;&amp;quot; as above. This server farm will represent the production environment. &lt;/li&gt;    &lt;li&gt;Select the server farm &amp;quot;&lt;strong&gt;pilotSiteServers&amp;quot;. &lt;/strong&gt;The following icons will be shown: &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/srv-farm.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="192" alt="srv-farm" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/srv-farm_thumb.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;Double click on &amp;quot;&lt;strong&gt;Routing&lt;/strong&gt; &lt;strong&gt;Rules&lt;/strong&gt;&amp;quot;. &lt;/li&gt;    &lt;li&gt;Since this scenario involves multiple server farms with conditional matching of HTTP request headers, we will use URL Rewrite UI which exposes additional options. Click on &amp;quot;&lt;strong&gt;URL Rewrite&lt;/strong&gt;&amp;quot; under &amp;quot;&lt;strong&gt;Advanced Routing&lt;/strong&gt;&amp;quot;. &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/adv.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="61" alt="adv" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/adv_thumb.png" width="201" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;You will note that two rules are already there. &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/twoRules.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="113" alt="twoRules" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/twoRules_thumb.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;These rules has to be changed. The order of rule is important. I will explain it in a while. For now, if &lt;strong&gt;ARR_productionSiteServers_loadbalance&lt;/strong&gt; is above &lt;strong&gt;ARR_pilotSiteServers_loadbalance&lt;/strong&gt;, change the order of the rules by using &lt;strong&gt;Move Up&lt;/strong&gt; or &lt;strong&gt;Move Down&lt;/strong&gt; after selecting the rule. &lt;/li&gt;    &lt;li&gt;Select &lt;strong&gt;ARR_pilotSiteServers_loadbalance&lt;/strong&gt;, and then click &lt;strong&gt;Edit...&lt;/strong&gt; in the &lt;strong&gt;Actions&lt;/strong&gt; pane. &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/edit.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="504" alt="edit" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/edit_thumb.png" width="504" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;We need to define conditions now. Remember our aim is to &amp;quot;redirect all users who have .NET Framework 3.5 installed and using the browser Internet Explorer to the pilot site&amp;quot; &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Add Conditions&lt;/strong&gt;, and then&lt;strong&gt; &lt;/strong&gt;click &lt;strong&gt;Add...&lt;/strong&gt;.       &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/add.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="289" alt="add" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/add_thumb.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;Enter &lt;strong&gt;{HTTP_USER_AGENT}&lt;/strong&gt; as &lt;strong&gt;Condition input&lt;/strong&gt; and &lt;strong&gt;*MSIE*&lt;/strong&gt; as &lt;strong&gt;Pattern&lt;/strong&gt;.&amp;#160; This condition checks to see if the client is using IE.       &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/add2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="289" alt="add2" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/add2_thumb.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;Add another condition to check for the .NET version.&amp;#160; Click &lt;strong&gt;Add...&lt;/strong&gt;, and then enter &lt;strong&gt;{HTTP_USER_AGENT}&lt;/strong&gt; as &lt;strong&gt;Condition input&lt;/strong&gt; and &lt;strong&gt;*.NET CLR 3.5*&lt;/strong&gt; as &lt;strong&gt;Pattern&lt;/strong&gt;.       &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/add3.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="289" alt="add3" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/add3_thumb.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;Finally, uncheck the &amp;quot;&lt;strong&gt;Stop processing of subsequent rules&amp;quot;&lt;/strong&gt; checkbox, and then click &amp;quot;&lt;strong&gt;Apply&amp;quot;&lt;/strong&gt; to save the changes.       &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/add4.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="137" alt="add4" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip36Didyouknow...Howtomanagepilotorbe.0_F0D4/add4_thumb.png" width="454" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;   &lt;/li&gt;    &lt;li&gt;Now let me answer why the order of rules mattered. This is because URL rewrite processes the rules in order when &amp;quot;&lt;strong&gt;Stop processing of subsequent rules&amp;quot;&lt;/strong&gt; is unselected.&amp;#160; So in this case the first rule &lt;strong&gt;ARR_pilotSiteServers_loadbalance &lt;/strong&gt;will be considered first.&amp;#160; This rule tries to match whether the client is using IE and has .NET Framework 3.5 installed.&amp;#160; If so, the requests are forwarded to the &lt;strong&gt;pilotSiteServers&lt;/strong&gt; server farm.&amp;#160; Since the &amp;quot;&lt;strong&gt;Stop processing of subsequent rules&amp;quot;&lt;/strong&gt; checkbox is unchecked, it will also process the second rule. This means the rule &lt;strong&gt;ARR_productionSiteServers_loadbalance&lt;/strong&gt; will also get processed. This will route all other request to &lt;strong&gt;productionSiteServers&lt;/strong&gt; server farm. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;That's it, we are done. For details regarding pre-requisite and command line equivalent of the above URL Rewrite rules look &lt;a href="http://learn.iis.net/page.aspx/487/pilot-program-management-using-application-request-routing/" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Don Raman      &lt;br /&gt;&lt;/strong&gt;SDET, &lt;a href="http://www.iis.net/"&gt;IIS Team&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9247655" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/IIS/default.aspx">IIS</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/URL+Rewrite/default.aspx">URL Rewrite</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/ARR/default.aspx">ARR</category></item><item><title>Tip #34: Did you know... How to stop hot-linking from your site using URL Rewrite in IIS 7.0?</title><link>http://blogs.msdn.com/webdevelopertips/archive/2008/12/15/tip-34-did-you-know-how-to-stop-hot-linking-from-your-site-using-url-rewrite-in-iis-7-0.aspx</link><pubDate>Mon, 15 Dec 2008 12:44:54 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9219567</guid><dc:creator>WebDevTools</dc:creator><slash:comments>10</slash:comments><comments>http://blogs.msdn.com/webdevelopertips/comments/9219567.aspx</comments><wfw:commentRss>http://blogs.msdn.com/webdevelopertips/commentrss.aspx?PostID=9219567</wfw:commentRss><description>&lt;p&gt;Hot-linking is a direct linking to a web-site's file (images, videos etc). An example can be using an &amp;lt;img&amp;gt; tag to display a JPEG image someone finds at your web site. This is also referred to as bandwidth theft as when someone is viewing this site, they will be using the bandwidth of your site to display the JPEG image. The other words used to describe this are leeching, piggybacking, direct linking or offsite image grabs to name a few.&lt;/p&gt;  &lt;p&gt;Let's say you have the below copyright image at your web site &lt;a href="http://www.contoso.com/img1.jpg"&gt;http://www.contoso.com/img1.jpg&lt;/a&gt; which you would like to prevent from hot linking.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip34Didyouknow...Howtostophotlinkingf.0_13EC/welcome_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="177" alt="welcome" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip34Didyouknow...Howtostophotlinkingf.0_13EC/welcome_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;URL Rewrite module in IIS 7.0 can be used to achieve this in a very simple way. I will tell you how to do this from IIS Manager. Open IIS Manager and select &amp;quot;Your Web Site (Contoso.com in this case)&amp;quot;. In the feature view click &amp;quot;URL Rewrite and click &amp;quot;Add Rules...&amp;quot; in the &amp;quot;Actions&amp;quot; pane. Select &amp;quot;Blank Rule&amp;quot; to start with. This will open up the &amp;quot;Edit Rule&amp;quot; property page. Fill the property page as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip34Didyouknow...Howtostophotlinkingf.0_13EC/Url_Rewrite_4.jpg"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="698" alt="Url_Rewrite" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip34Didyouknow...Howtostophotlinkingf.0_13EC/Url_Rewrite_thumb_1.jpg" width="529" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Let me now explain what we have done on this property page:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Specified name of the rule as &amp;quot;Prevent Leeching&amp;quot;. This must be a unique rule. &lt;/li&gt;    &lt;li&gt;Every requested URL will be matched as the pattern is &amp;quot;.*&amp;quot; and is a regular expression. &lt;/li&gt;    &lt;li&gt;Added two condition and specified both the condition to be satisfied (see &amp;quot;Logical Grouping&amp;quot; is &amp;quot;Match All&amp;quot;)      &lt;ul&gt;       &lt;li&gt;HTTP_REFERRER does not match empty as it can be a direct reference to the image &lt;/li&gt;        &lt;li&gt;HTTP_REFERRER does not match my own site &lt;a href="http://www.contoso.com"&gt;http://www.contoso.com&lt;/a&gt; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;If the above two conditions are satisfied (apparently meaning the request is coming from any other site), we are just redirecting it to pick up some other image which can be anything &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;And that's it. So without writing even a single line of code we are able to prevent hot-linking.&lt;/p&gt;  &lt;p&gt;One important thing to remember is that URL Rewrite should be installed for this to work. You can install X86 version &lt;a href="http://www.iis.net/downloads/default.aspx?tabid=34&amp;amp;g=6&amp;amp;i=1691"&gt;here&lt;/a&gt; and X64 &lt;a href="http://www.iis.net/downloads/default.aspx?tabid=34&amp;amp;g=6&amp;amp;i=1692"&gt;here&lt;/a&gt;. This module is supported for IIS 7.0 and you should be running IIS 7.0 to take advantage of it. Also if you are working with VWD (Visual Studio for Web Developers) your project should be configured to work with IIS 7.0 and not any other web server.&lt;/p&gt;  &lt;p&gt;This was one of the cool features showcased in PDC 2008 for IIS 7.0. For other cool features including this please see this complete video at &lt;a href="http://channel9.msdn.com/pdc2008/ES14/" target="_blank"&gt;channel9&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Don Raman&amp;#160; &lt;br /&gt;&lt;/strong&gt;SDET, &lt;a href="http://www.iis.net/"&gt;IIS Team&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9219567" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/IIS/default.aspx">IIS</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/URL+Rewrite/default.aspx">URL Rewrite</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/Hotlinking/default.aspx">Hotlinking</category></item><item><title>Tip#25: Did you know... You can have canonical URLs and Redirects with IIS 7.0</title><link>http://blogs.msdn.com/webdevelopertips/archive/2008/11/20/tip-25-did-you-know-you-can-have-canonical-urls-and-redirects-with-iis-7-0.aspx</link><pubDate>Thu, 20 Nov 2008 04:57:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9126976</guid><dc:creator>WebDevTools</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/webdevelopertips/comments/9126976.aspx</comments><wfw:commentRss>http://blogs.msdn.com/webdevelopertips/commentrss.aspx?PostID=9126976</wfw:commentRss><description>&lt;p&gt;Canonical URLs help you to make your links Search Engine Optimized (SEO). For human it is easy to understand that &lt;a href="http://www.contoso.com"&gt;http://www.contoso.com&lt;/a&gt; is same as &lt;a href="http://contoso.com"&gt;http://contoso.com&lt;/a&gt;. But many search engines will not make this assumption and treat them as two separate entries. This will split the rankings among them and lower the overall relevance of the site.&lt;/p&gt;  &lt;p&gt;In IIS7.0 you can use URL Rewrite to solve this problem. The following rule when added in the &amp;quot;Web.config&amp;quot; file in the root of your web site will automatically direct all the people using &lt;a href="http://contoso.com"&gt;http://contoso.com&lt;/a&gt; to &lt;a href="http://www.contoso.com"&gt;http://www.contoso.com&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;pre&gt;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;system.webServer&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;rewrite&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;rules&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;rule&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #000000"&gt;name&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;WWW Redirect&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #000000"&gt;stopProcessing&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;
          &amp;lt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;match&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #000000"&gt;url&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;.*&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt; /&amp;gt;
          &amp;lt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;conditions&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;add&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #000000"&gt;input&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;{HTTP_HOST}&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #000000"&gt;pattern&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;^&lt;/span&gt;&lt;span style="color: #0000ff"&gt;contoso.com$&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt; /&amp;gt;
          &amp;lt;/&lt;/span&gt;&lt;span style="color: #ff0000"&gt;conditions&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;
          &amp;lt;&lt;/span&gt;&lt;span style="color: #ff0000"&gt;action&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #000000"&gt;type&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;Redirect&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;span style="color: #000000"&gt;url&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&lt;a href="http://www.contoso.com/{R:0"&gt;http://www.contoso.com/{R:0&lt;/a&gt;}&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt; &lt;/span&gt;&lt;/pre&gt;

&lt;pre&gt;&lt;span style="color: #0000ff"&gt;&lt;/span&gt;&lt;span style="color: #000000"&gt;redirectType&lt;/span&gt;&lt;span style="color: #0000ff"&gt;=&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt;Permanent&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #0000ff"&gt; /&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #ff0000"&gt;rule&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="color: #ff0000"&gt;rules&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #ff0000"&gt;rewrite&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;
  &amp;lt;/&lt;/span&gt;&lt;span style="color: #ff0000"&gt;system.webServer&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #ff0000"&gt;configuration&lt;/span&gt;&lt;span style="color: #0000ff"&gt;&amp;gt;
&amp;lt;/PRE&amp;lt; P&amp;gt;&lt;p&gt;&amp;#160;&lt;/p&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;One important thing to remember is to use &amp;quot;Permanent&amp;quot; redirects. This will be helpful if anybody who has linked your page using a non WWW URL. Doing this will direct search engine bot crawls to treat the link as permanently moved. The new URL will be identified as the correct address hence old non WWW URL will not be indexed.&lt;/p&gt;

&lt;p&gt;I have just pasted the XML code but the same thing can be achieved using the URL Rewrite GUI which comes with IIS Manager. &lt;/p&gt;

&lt;p&gt;Open IIS Manager.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.YoucanhavecanonicalURLsandRedirectsw_A5D6/IIS_Manager_4.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="198" alt="IIS_Manager" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.YoucanhavecanonicalURLsandRedirectsw_A5D6/IIS_Manager_thumb_1.jpg" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Click on URL Rewrite.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.YoucanhavecanonicalURLsandRedirectsw_A5D6/Url_Rewrite_4.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="198" alt="Url_Rewrite" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.YoucanhavecanonicalURLsandRedirectsw_A5D6/Url_Rewrite_thumb_1.jpg" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Click on Add Rules-&amp;gt;Blank Rule.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.YoucanhavecanonicalURLsandRedirectsw_A5D6/image_4.png"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="167" alt="image" src="http://blogs.msdn.com/blogfiles/webdevelopertips/WindowsLiveWriter/Tip.YoucanhavecanonicalURLsandRedirectsw_A5D6/image_thumb_1.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Give a pattern you would like to match, change the &amp;#8220;Action type&amp;#8221; to &amp;#8220;Redirect&amp;#8221; and specify the redirect URL. This will add the same content to the config file as shown above. &lt;/p&gt;

&lt;p&gt;One important thing to remember is that URL Rewrite should be installed for this to work. You can install X86 version &lt;a href="http://www.iis.net/downloads/default.aspx?tabid=34&amp;amp;g=6&amp;amp;i=1691" target="_blank"&gt;here&lt;/a&gt; and X64 &lt;a href="http://www.iis.net/downloads/default.aspx?tabid=34&amp;amp;g=6&amp;amp;i=1692" target="_blank"&gt;here&lt;/a&gt;. This module is supported for IIS 7.0 and you should be running IIS 7.0 to take advantage of it. Also if you are working with VWD (Visual Studio for Web Developers) your project should be configured to work with IIS 7.0 and not any other web server.&lt;/p&gt;

&lt;p&gt;For details about URL Rewrite module please look &lt;a href="http://learn.iis.net/page.aspx/460/using-url-rewrite-module/" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Don Raman&amp;#160; &lt;br /&gt;&lt;/strong&gt;SDET, &lt;a href="http://www.iis.net/" target="_blank"&gt;IIS Team&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9126976" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/IIS/default.aspx">IIS</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/Canonical+URL/default.aspx">Canonical URL</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/URL+Redirect/default.aspx">URL Redirect</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/SEO/default.aspx">SEO</category><category domain="http://blogs.msdn.com/webdevelopertips/archive/tags/URL+Rewrite/default.aspx">URL Rewrite</category></item></channel></rss>