ScriptManager EnableCdn 在 SSL 上无效。

5

我正在尝试在ScriptManager中使用EnableCdn属性。基本上,我在我的主页文件中有以下代码:

<asp:ScriptManager ID="MainScriptManager" runat="server" EnablePartialRendering="true"
    EnableScriptGlobalization="true" EnableScriptLocalization="true" AsyncPostBackTimeout="3600" EnableCdn="True">

这在我们通过 HTTP 连接的开发环境中可以运行 - 它引用了这样的脚本:
<script src="http://ajax.aspnetcdn.com/ajax/4.5/5/WebForms.js" type="text/javascript"></script>

但是在我们使用SSL的生产服务器上,它尝试包含这样的脚本:
<script src="https://ajax.microsoft.com/ajax/4.0/2/WebForms.js" type="text/javascript"></script>

有两个不同之处(版本和域),但最重要的是版本4.0的此文件不在CDN服务器上(通过https!)。
是否有人能提出解决这个问题的建议?这是否意味着版本4.0不支持https,但通过http支持(我可以通过这两种方法下载版本4.5的文件,但仅通过HTTP可用版本4.0)。
编辑:
我已经找到信息,“ajax.microsoft.com更名为ajax.aspnetcdn.com” - 这似乎是我的版本的问题,但我还没有找到如何将域更改为正确的信息(尚未)。我们应该在生产环境中重新安装框架吗?

你能确认你的生产环境和开发环境运行的是相同版本的.NET吗?看起来你的开发环境正在运行.NET 4.5 RC,而你的生产环境则是.NET 4.0。 - Damian Edwards
那似乎是个问题 - 我已经要求发布团队在我们的生产环境上安装.NET 4.5 RTM。 - tomkuj
3个回答

7

文件已经在服务器上,但是最近它一直表现得很不稳定(现在甚至无法访问任何文件),因此请始终使用本地故障转移。

对于 .Net 4.0,只需将以下内容添加到您的 Global.asax 文件中 - 它会使用新的 CDN 域更新所有链接(对于早期版本,请适当更改链接):

protected void Application_Start(object sender, EventArgs e)
{
    System.Reflection.Assembly web = typeof(HttpApplication).Assembly;
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "WebForms.js",
        web,
        new ScriptResourceDefinition
        {
            ResourceName = "WebForms.js",
            ResourceAssembly = web,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/WebForms.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/WebForms.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "Focus.js",
        web,
        new ScriptResourceDefinition
        {
            ResourceName = "Focus.js",
            ResourceAssembly = web,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/Focus.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/Focus.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "SmartNav.js",
        web,
        new ScriptResourceDefinition
        {
            ResourceName = "SmartNav.js",
            ResourceAssembly = web,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/SmartNav.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/SmartNav.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "WebUIValidation.js",
        web,
        new ScriptResourceDefinition
        {
            ResourceName = "WebUIValidation.js",
            ResourceAssembly = web,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/WebUIValidation.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/WebUIValidation.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "TreeView.js",
        web,
        new ScriptResourceDefinition
        {
            ResourceName = "TreeView.js",
            ResourceAssembly = web,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/TreeView.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/TreeView.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "Menu.js",
        web,
        new ScriptResourceDefinition
        {
            ResourceName = "Menu.js",
            ResourceAssembly = web,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/Menu.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/Menu.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "MenuStandards.js",
        web,
        new ScriptResourceDefinition
        {
            ResourceName = "MenuStandards.js",
            ResourceAssembly = web,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MenuStandards.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MenuStandards.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "WebParts.js",
        web,
        new ScriptResourceDefinition
        {
            ResourceName = "WebParts.js",
            ResourceAssembly = web,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/WebParts.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/WebParts.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "GridView.js",
        web,
        new ScriptResourceDefinition
        {
            ResourceName = "GridView.js",
            ResourceAssembly = web,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/GridView.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/GridView.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "DetailsView.js",
        web,
        new ScriptResourceDefinition
        {
            ResourceName = "DetailsView.js",
            ResourceAssembly = web,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/DetailsView.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/DetailsView.js",
            CdnSupportsSecureConnection = true
        }
    );
    System.Reflection.Assembly ext = typeof(ScriptManager).Assembly;
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "MicrosoftAjax.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "MicrosoftAjax.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjax.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjax.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "MicrosoftAjaxApplicationServices.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "MicrosoftAjaxApplicationServices.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxApplicationServices.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxApplicationServices.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "MicrosoftAjaxComponentModel.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "MicrosoftAjaxComponentModel.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxComponentModel.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxComponentModel.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "MicrosoftAjaxCore.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "MicrosoftAjaxCore.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxCore.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxCore.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "MicrosoftAjaxGlobalization.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "MicrosoftAjaxGlobalization.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxGlobalization.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxGlobalization.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "MicrosoftAjaxHistory.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "MicrosoftAjaxHistory.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxHistory.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxHistory.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "MicrosoftAjaxNetwork.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "MicrosoftAjaxNetwork.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxNetwork.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxNetwork.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "MicrosoftAjaxSerialization.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "MicrosoftAjaxSerialization.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxSerialization.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxSerialization.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "MicrosoftAjaxTimer.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "MicrosoftAjaxTimer.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxTimer.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxTimer.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "MicrosoftAjaxWebForms.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "MicrosoftAjaxWebForms.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxWebForms.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxWebForms.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "MicrosoftAjaxWebServices.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "MicrosoftAjaxWebServices.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxWebServices.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/MicrosoftAjaxWebServices.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "Date.HijriCalendar.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "Date.HijriCalendar.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/Date.HijriCalendar.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/Date.HijriCalendar.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
    ScriptManager.ScriptResourceMapping.AddDefinition(
        "Date.UmAlQuraCalendar.js",
        ext,
        new ScriptResourceDefinition
        {
            ResourceName = "Date.UmAlQuraCalendar.js",
            ResourceAssembly = ext,
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/Date.UmAlQuraCalendar.js",
            CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/4.0/2/Date.UmAlQuraCalendar.debug.js",
            CdnSupportsSecureConnection = true
        }
    );
}

0

结账 此链接

我知道这并没有解决所问的问题。但是这更清楚地说明了我们如何使用它,因为这个链接很好地解释了它。它具有类似于“Nikola Bogdanovic”提到的语法,但它还包括本地路径,以防CDN无法响应请求。

例如(示例代码):

string str = "1.7.1";

ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition

{

    Path = "~/Scripts/jquery-" + str + ".min.js", 

    DebugPath = "~/Scripts/jquery-" + str + ".js", 

    CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + str + ".min.js", 

    CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + str + ".js", 

    CdnSupportsSecureConnection = true, 

    LoadSuccessExpression = "window.jQuery"

});

“LoadSuccessExpression” 属性是在 .Net 4.5 中添加的 - 在我回答时它还不存在... 那时你必须手动进行本地故障转移。 - Nikola Bogdanović

0

我也遇到了同样的问题,运行4.0版本时我找不到任何指示如何解决此问题的信息,因为引用ajax.microsoft.com的参考是由框架本身放置的。


我会尝试安装.NET 4.5 RTM并验证问题是否仍然存在。 - tomkuj

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接