locked
Script Manager Not Using CDN on Remote Host for MS AJAX RRS feed

  • Question

  • User-939035612 posted

    I have a ScriptManager configured to use the CDN. It works great for everything except AJAX remotely. If I load the site on my local machine via all the AJAX scripts run off the CDN like they should, but when I upload it to my remote server I see no references to the CDN for AJAX and a bunch of references to ScriptResource.axd. What could cause the site not to use the CDN only on the remote host?

    Here is the Script Manager

     <asp:ScriptManager runat="server" EnableHistory="true" EnableSecureHistoryState="false" EnableCdn="True" EnableCdnFallback="True">
                <Scripts>
                    <%--To learn more about bundling scripts in ScriptManager see http://go.microsoft.com/fwlink/?LinkID=301884 --%>
                    <%--Framework Scripts--%>
                    <asp:ScriptReference Name="MsAjaxBundle" />
                    <asp:ScriptReference Name="jquery" />
                    <asp:ScriptReference Name="popper" />
                    <asp:ScriptReference Name="bootstrap" />
                    <asp:ScriptReference Name="respond" />
                    <asp:ScriptReference Name="lazysizes" />
                    <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
                    <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
                    <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
                    <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
                    <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
                    <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
                    <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
                    <asp:ScriptReference Name="WebFormsBundle" />
                    <%--Site Scripts--%>
                </Scripts>
                <Services>
                    <asp:ServiceReference Path="/webservices/TagSearch.asmx" />
                    <asp:ServiceReference Path="/webservices/CitySearch.asmx" />
                     <asp:ServiceReference Path="/webservices/DCNames.asmx" />
                     <asp:ServiceReference Path="/webservices/DCAgencies.asmx" />
                    <asp:ServiceReference Path="/webservices/ExternalLink.asmx" />
                    <asp:ServiceReference Path="/webservices/insertdsc.asmx" />
                </Services>
            </asp:ScriptManager>

    Here is the BundleConfig.cs file

    public class BundleConfig
        {
            // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkID=303951
            public static void RegisterBundles(BundleCollection bundles)
            {
                bundles.Add(new ScriptBundle("~/bundles/WebFormsJs").Include(
                                "~/Scripts/WebForms/WebForms.js",
                                "~/Scripts/WebForms/WebUIValidation.js",
                                "~/Scripts/WebForms/MenuStandards.js",
                                "~/Scripts/WebForms/Focus.js",
                                "~/Scripts/WebForms/GridView.js",
                                "~/Scripts/WebForms/DetailsView.js",
                                "~/Scripts/WebForms/TreeView.js",
                                "~/Scripts/WebForms/WebParts.js"));
    
                // Order is very important for these files to work, they have explicit dependencies
                bundles.Add(new ScriptBundle("~/bundles/MsAjaxJs").Include(
                        "~/Scripts/WebForms/MsAjax/MicrosoftAjax.js",
                        "~/Scripts/WebForms/MsAjax/MicrosoftAjaxApplicationServices.js",
                        "~/Scripts/WebForms/MsAjax/MicrosoftAjaxTimer.js",
                        "~/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js"));
    
    
                // Use the Development version of Modernizr to develop with and learn from. Then, when you’re
                // ready for production, use the build tool at http://modernizr.com to pick only the tests you need
                bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                                "~/Scripts/modernizr-*"));
                
                ScriptManager.ScriptResourceMapping.AddDefinition(
                    "respond",
                    new ScriptResourceDefinition
                    {
                        Path = "~/Scripts/respond.min.js",
                        DebugPath = "~/Scripts/respond.js",
                        CdnPath = "https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.0/respond.min.js",
                        CdnDebugPath = "https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.0/respond.js",
                        CdnSupportsSecureConnection = true
    
                    });
                ScriptManager.ScriptResourceMapping.AddDefinition(
                    "popper",
                    new ScriptResourceDefinition
                    {
                        Path = "~/Scripts/umd/popper.min.js",
                        DebugPath = "~/Scripts/umd.popper.js",
                        CdnPath = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js",
                        CdnDebugPath = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.js",
                        CdnSupportsSecureConnection = true,
                    });
                ScriptManager.ScriptResourceMapping.AddDefinition(
                    "lazysizes",
                    new ScriptResourceDefinition
                    {
                        Path = "~/lib/lazysizes/lazysizes.min.js",
                        DebugPath = "~/lib/lazysizes/lazysizes.js",
                        CdnPath = "https://cdnjs.cloudflare.com/ajax/libs/lazysizes/5.2.2/lazysizes.min.js",
                        CdnDebugPath = "https://cdnjs.cloudflare.com/ajax/libs/lazysizes/5.2.2/lazysizes.js",
                        CdnSupportsSecureConnection = true,
                    });
            }
        }

    Here is the source code from a page running on my local machine WITHOUT SSL

    <script src="http://ajax.aspnetcdn.com/ajax/4.5.1/1/MsAjaxBundle.js" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    (window.Sys)||document.write('<script type="text/javascript" src="/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81"><\/script>');//]]>
    </script>
    
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.5.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    (window.jQuery)||document.write('<script type="text/javascript" src="Scripts/jquery-3.5.1.min.js"><\/script>');//]]>
    </script>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" type="text/javascript"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/bootstrap/4.5.3/bootstrap.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    (window.jQuery.fn.carousel)||document.write('<script type="text/javascript" src="Scripts/bootstrap.min.js"><\/script>');//]]>
    </script>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.0/respond.min.js" type="text/javascript"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/lazysizes/5.2.2/lazysizes.min.js" type="text/javascript"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/4.5.1/1/WebFormsBundle.js" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    (window.WebForm_PostBackOptions)||document.write('<script type="text/javascript" src="/bundles/WebFormsJs?v=N8tymL9KraMLGAMFuPycfH3pXe6uUlRXdhtYv8A_jUU1"><\/script>');//]]>
    </script>
    
    <script src="//ajax.aspnetcdn.com/ajax/act/16_1_1/Scripts/AjaxControlToolkit/Release/Localization.Resources.js" type="text/javascript"></script>
    <script src="//ajax.aspnetcdn.com/ajax/act/16_1_1/Scripts/AjaxControlToolkit/Release/ComponentSet.js" type="text/javascript"></script>
    <script src="//ajax.aspnetcdn.com/ajax/act/16_1_1/Scripts/AjaxControlToolkit/Release/Common.js" type="text/javascript"></script>
    <script src="//ajax.aspnetcdn.com/ajax/act/16_1_1/Scripts/AjaxControlToolkit/Release/BaseScripts.js" type="text/javascript"></script>
    <script src="//ajax.aspnetcdn.com/ajax/act/16_1_1/Scripts/AjaxControlToolkit/Release/CascadingDropDown.js" type="text/javascript"></script>
    <script src="//ajax.aspnetcdn.com/ajax/act/16_1_1/Scripts/AjaxControlToolkit/Release/Compat.Timer.js" type="text/javascript"></script>
    <script src="//ajax.aspnetcdn.com/ajax/act/16_1_1/Scripts/AjaxControlToolkit/Release/AnimationScripts.js" type="text/javascript"></script>
    <script src="//ajax.aspnetcdn.com/ajax/act/16_1_1/Scripts/AjaxControlToolkit/Release/Animation.js" type="text/javascript"></script>
    <script src="//ajax.aspnetcdn.com/ajax/act/16_1_1/Scripts/AjaxControlToolkit/Release/Popup.js" type="text/javascript"></script>
    <script src="//ajax.aspnetcdn.com/ajax/act/16_1_1/Scripts/AjaxControlToolkit/Release/AutoComplete.js" type="text/javascript"></script>
    <script src="//ajax.aspnetcdn.com/ajax/act/16_1_1/Scripts/AjaxControlToolkit/Release/TextBoxWatermark.js" type="text/javascript"></script>
    <script src="//ajax.aspnetcdn.com/ajax/act/16_1_1/Scripts/AjaxControlToolkit/Release/UpdatePanelAnimation.js" type="text/javascript"></script>
    <script src="/webservices/TagSearch.asmx/js" type="text/javascript"></script>
    <script src="/webservices/CitySearch.asmx/js" type="text/javascript"></script>
    <script src="/webservices/DCNames.asmx/js" type="text/javascript"></script>
    <script src="/webservices/DCAgencies.asmx/js" type="text/javascript"></script>
    <script src="/webservices/ExternalLink.asmx/js" type="text/javascript"></script>
    <script src="/webservices/insertdsc.asmx/js" type="text/javascript"></script>
    <script type="text/javascript">

    Here is the source code from the website running live on a remote IIS server:

    <script src="https://ajax.aspnetcdn.com/ajax/4.5.1/1/MsAjaxBundle.js" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    (window.Sys)||document.write('<script type="text/javascript" src="/bundles/MsAjaxJs?v=D6VN0fHlwFSIWjbVzi6mZyE9Ls-4LNrSSYVGRU46XF81"><\/script>');//]]>
    </script>
    
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.5.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    (window.jQuery)||document.write('<script type="text/javascript" src="Scripts/jquery-3.5.1.min.js"><\/script>');//]]>
    </script>
    
    <script src="Scripts/umd/popper.min.js" type="text/javascript"></script>
    <script src="https://ajax.aspnetcdn.com/ajax/bootstrap/4.5.3/bootstrap.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    (window.jQuery.fn.carousel)||document.write('<script type="text/javascript" src="Scripts/bootstrap.min.js"><\/script>');//]]>
    </script>
    
    <script src="Scripts/respond.min.js" type="text/javascript"></script>
    <script src="https://ajax.aspnetcdn.com/ajax/4.5.1/1/WebFormsBundle.js" type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[
    (window.WebForm_PostBackOptions)||document.write('<script type="text/javascript" src="/bundles/WebFormsJs?v=N8tymL9KraMLGAMFuPycfH3pXe6uUlRXdhtYv8A_jUU1"><\/script>');//]]>
    </script>
    
    <script src="/ScriptResource.axd?d=eE6V8nDbUVn0gtG6hKNX_H5ly8e9cwxzW3q3vRJPfy5skbgRrovnomPG4i-h8-d3URvm-BPODK02iP8oaS4AZfYR4BiyYXFsaVSYY9QcjqyqnilXJjhUWqOcqVTI5DPC0&amp;t=ffffffffcfeeeb28" type="text/javascript"></script>
    <script src="/ScriptResource.axd?d=jwf4VSQi7LeShc44FJ-gAe5nni8SKiHof9ZpQXs-RIqwUNUqLFFgjipEpwtQR-HdpV3nHtMrhPO0onBjDVm73D4snDHSSC7pE-FO4MramILqRP7aD5eMGMYTp4VujgV-0&amp;t=ffffffffcfeeeb28" type="text/javascript"></script>
    <script src="/ScriptResource.axd?d=mcAASOSteirJeuV-3by3UbEn3p-mpdEcd1sRA5zInOh5TNPuPOJnQC8ASiooha3dRVIASfQpjfCo3G8nxlSoPoF4irYbgDnV1u_fy27DOYw1&amp;t=ffffffffcfeeeb28" type="text/javascript"></script>
    <script src="/ScriptResource.axd?d=HEFpVKbnoeQjkjHkFKu3MMEOEafgbVZ21KhB8D80Ha46LrKCIclUprKqt-chXd8DvgfQLHtzMALj7PxoL2LhO2-AJpoqJE5qoAfQD4BQMBmAmLUIWArdvlLTBFLVIE7-0&amp;t=ffffffffcfeeeb28" type="text/javascript"></script>
    <script src="/ScriptResource.axd?d=sw781r6OAlXlgwOkqK1g8vRL1gCOI082752n9cj6l_PwUzfIN331R-tMsK98gWqplWSx2_ykkxvFj9S4te_rsL3mBmj9x_AsP-yNWx-2-OSJvL-s3KFo3ia_KJK9S_S40&amp;t=ffffffffcfeeeb28" type="text/javascript"></script>
    <script src="/ScriptResource.axd?d=nai7mGcYyE2dix_TwveLDU9hmnp2XRKb_GClCOjfmCRDTLnd4hDl_EOgL6WCiUoZvwMXDNgizxeX5PM-aeDhKJMteSrc-bZne7Lpr26_bb_Lga5MMY3WSjGinUMAKpRD0&amp;t=ffffffffcfeeeb28" type="text/javascript"></script>
    <script src="/ScriptResource.axd?d=LQ1q2RBSthBAZhliMjtG_1T0ECJHFAyC5NiFu2Wj5NEqL4QpERixjF7MtUOW1G62iCbvY6qDJrM_oXE_ySI21o6_twYXyZ45epRK_QMEf4Kcms7I-3Z3VloXhwZaXUWb0&amp;t=ffffffffcfeeeb28" type="text/javascript"></script>
    <script src="/ScriptResource.axd?d=VOYD8Xe7kQA0lniBYXVpAiYSLexe236H8TylBEHjjLQrEUCj3CRrI2mntk_zsqaRzybrbJ5JOVo5JnP4Ezh1Fh7x6UPieAoTp6Nhxorg3llDUh2FDoajMe5GtgDGPtoJ0&amp;t=ffffffffcfeeeb28" type="text/javascript"></script>
    <script src="/ScriptResource.axd?d=24039AtbfhsNBYQDFUMYHMdbUXMO2ih8tRvYOZ9cyxyGun2Q123pf-U1c1ngne7bMi1-sqi39mqodYMe8DAHixb23kJSs787mYEBnHdNbRs1&amp;t=ffffffffcfeeeb28" type="text/javascript"></script>
    <script src="/ScriptResource.axd?d=iDJsJb59XB5efowLsFnqUBzvj-eE812QeUALGtnyR1TQB8oRxJFt4Znw9KYsG76Wpml5vLzQ32wZD6u7RS4Tvz2R5mOPcHatHsUONHdz4r2-Hc7mXmrA7V6iKnYEc_z00&amp;t=ffffffffcfeeeb28" type="text/javascript"></script>
    <script src="/ScriptResource.axd?d=X6kQKInQS5YQqruiTh57iCbkLgl8IAfvnxKXjXy_ZB1jh5R4j5t9CdT5_OYNkCMQe8PuGgkWLVLh_BnnaWCecpOfcqBGBvTqFVbpJVKZz-SP-hMplkN-SUxIcWsDVd710&amp;t=ffffffffcfeeeb28" type="text/javascript"></script>
    <script src="/ScriptResource.axd?d=GhMTAxdxy2a-Wl-WY5EfmYGG8LhUPcKJ65XafKrF36RFcXRIIrawXrLK-7RA9FGLZA4gvHHf3EMbIQhVdsOr5i4iQC2KRicTVjh_fBALGfJG0vSPPXcl4bEWkvvLSlD40&amp;t=ffffffffcfeeeb28" type="text/javascript"></script>
    <script src="webservices/CitySearch.asmx/js" type="text/javascript"></script>
    <script src="webservices/TagSearch.asmx/js" type="text/javascript"></script>
    <script src="webservices/DCNames.asmx/js" type="text/javascript"></script>
    <script src="webservices/DCAgencies.asmx/js" type="text/javascript"></script>
    <script src="webservices/ExternalLink.asmx/js" type="text/javascript"></script>
    <script src="webservices/insertdsc.asmx/js" type="text/javascript"></script>
    <script src="webservices/Category.asmx/js" type="text/javascript"></script>

    UPDATE: Seems the problem is solely with the AJAX Control Toolkit and Nothing else. I am guessing since my remote server supports SSL only and upgrades insecure request that has something to do with it..

    Tuesday, December 29, 2020 9:28 AM

Answers

  • User-939850651 posted

    Hi CopBlaster,

    Do you mean you need to use custom scripts or third-party controls?

    If this is the case, when you embed a script within an assembly for use by a WebForm, you have to define a WebResourceAttribute for it, which allows it to be accessed via the WebResource.axd or ScriptResource.axd handlers.

    Something like :

    [assembly: WebResource("Foo.js", "application/x-javascript", CdnPath = "http://foo.com/foo/bar/foo.js")]

    ScriptManager looks for this property when the EnableCdn property is set to true, and simply uses that path instead of the ScriptResource.axd path to the assembly resource. And this means that you too can provide your own CDN paths for your own assembly resource scripts. As for where to host your script, well, that’s up to you.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 5, 2021 2:32 AM

All replies

  • User-939850651 posted

    Hi CopBlaster,

    According to your description, I made a related inquiry about this issue. I have found that if an assembly does not define a CDN path in its WebResourceAttributes, EnableCDN won't know where to go.

    I see that you have added the appropriate CDN path for the corresponding reference, so I think the problem may be related to what you described at the end.

    I found a good article about this:

    https://weblogs.asp.net/infinitiesloop/asp-net-4-0-scriptmanager-improvements

    Best regards,

    Xudong Peng

    Wednesday, December 30, 2020 10:32 AM
  • User-939035612 posted

    Thanks XuDong,

    My next question would be if it would be possible for me to define a CDN for the AJAXControlToolkit myself. I don't know how I would do that since I don't know of a way for me to edit assemblies created by others.

    Thursday, December 31, 2020 10:17 AM
  • User-939850651 posted

    Hi CopBlaster,

    Do you mean you need to use custom scripts or third-party controls?

    If this is the case, when you embed a script within an assembly for use by a WebForm, you have to define a WebResourceAttribute for it, which allows it to be accessed via the WebResource.axd or ScriptResource.axd handlers.

    Something like :

    [assembly: WebResource("Foo.js", "application/x-javascript", CdnPath = "http://foo.com/foo/bar/foo.js")]

    ScriptManager looks for this property when the EnableCdn property is set to true, and simply uses that path instead of the ScriptResource.axd path to the assembly resource. And this means that you too can provide your own CDN paths for your own assembly resource scripts. As for where to host your script, well, that’s up to you.

    Best regards,

    Xudong Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, January 5, 2021 2:32 AM