<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">AJAX - Kennydust</title>
  <icon>http://www.kennydust.com/Content/icons/flame.ico</icon>
  <logo>http://www.kennydust.com/Content/icons/flame.png</logo>
  <updated>2010-03-02T18:39:00</updated>
  <subtitle type="html">Thoughts from a C# Developer</subtitle>
  <id>http://www.kennydust.com/site.aspx/tags/ajax/atom</id>
  <link rel="alternate" type="text/html" hreflang="en" href="/site.aspx/tags/ajax/atom"/>
  <link rel="self" type="application/atom+xml" href="http://www.kennydust.com/site.aspx/Tags/AJAX/ATOM"/>
  <generator uri="http://oxite.net" version="1.0">Oxite</generator>
  <entry>
    <title type="html">Microsoft AJAX CDN for ASP.NET 3.5</title>
    <link rel="alternate" type="text/html" href="http://www.kennydust.com/site.aspx/Blog/Microsoft-AJAX-CDN-for-ASPNET-35"/>
    <id>http://www.kennydust.com/site.aspx/Blog/Microsoft-AJAX-CDN-for-ASPNET-35</id>
    <updated>2010-03-03T16:58:47.873</updated>
    <published>2010-03-02T18:39:00</published>
    <author>
      <name>kennydust</name>
    </author>
    <category term="AJAX" />
    <category term="CDN" />
    <content type="html" xml:lang="en">
      &lt;p&gt;Late last year, &lt;a href=&quot;http://weblogs.asp.net/scottgu/archive/2009/09/15/announcing-the-microsoft-ajax-cdn.aspx&quot; target=&quot;_blank&quot;&gt;Microsoft announced&lt;/a&gt; the launch of their caching support service aka their &lt;a href=&quot;http://www.asp.net/ajaxlibrary/CDN.ashx&quot; target=&quot;_blank&quot;&gt;CDN service&lt;/a&gt;, for their ASP.NET AJAX libraries (and the third party jquery libraries) at no cost. Sweet!&lt;/p&gt;  &lt;p&gt;The problem was, you needed to be up-to-date on ASP.NET 4.0 framework stack in order to take advantage of it. Luckily, the community banned together in an uproar, and shortly thereafter a fix was released. While it’s practically plug-and-play if you’ve running ASP.NET 4.0, some custom code is required to get it to work correctly in the 3.5 framework. I ran across an excellent &lt;a href=&quot;http://blog.turlov.com/2009/11/using-microsoft-ajax-library-35-with.html&quot; target=&quot;_blank&quot;&gt;blog&lt;/a&gt; about this, and it details much more than I was looking for.&lt;/p&gt;  &lt;p&gt;To paraphrase, you need to define a &amp;lt;script&amp;gt; region in your scriptmanager instance and hardcode the CDN path, this will override the default local script reference location:&lt;/p&gt;  

&lt;pre class=&quot;brush: xml;&quot;&gt;
&lt;asp:scriptmanager runat=&quot;server&quot; enablepartialrendering=&quot;false&quot;&gt;
  &lt;scripts&gt;           
    &lt;asp:scriptreference name=&quot;MicrosoftAjax.js&quot; path=&quot;http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.js&quot; /&gt;
  &lt;/scripts&gt;  
&lt;/asp:ScriptManager&gt;
&lt;/pre&gt;

&lt;p&gt;I wanted to encapulate the logic a little better, so I wrote a small control that inherits the scriptmanager, and conditionally loads from the CDN, because I work without an internet connection at times:&lt;/p&gt;
&lt;pre class=&quot;brush: c#;&quot;&gt;
    public class CustomScriptManagerControl : ScriptManager
    {
        /// &lt;summary&gt;
        /// Microsoft Ajax 3.5 reference.
        /// &lt;/summary&gt;
        private const string CDN_PATH = &quot;http://ajax.microsoft.com/ajax/3.5/MicrosoftAjax.js&quot;;

        protected override void OnInit(EventArgs e)
        {

#if !DEBUG
            Scripts.Add(new ScriptReference { Name = &quot;MicrosoftAjax.js&quot;, Path = CDN_PATH });
#endif

            base.OnInit(e);
        }
    }
&lt;/pre&gt;

&lt;p&gt;this is called in my consuming page:&lt;/p&gt;
&lt;pre class=&quot;brush: xml;&quot;&gt;
&lt;c:CustomScriptManagerControl runat=&quot;server&quot; EnablePartialRendering=&quot;true&quot; /&gt;
&lt;/pre&gt;
    </content>
  </entry>
</feed>

