asp.net - ScriptManager EnableCdn - 不适用于 SSL

标签 asp.net webforms scriptmanager microsoft-cdn

我正在尝试在 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 版本下载文件,但 4.0 只能通过 HTTP 获取)。

编辑:

我发现“ajax.microsoft.com 重命名为 ajax.aspnetcdn.com”的信息 - 这似乎是我的版本的问题,但我无法找到信息(尚未)如何将域更改为正确的域。我们应该在生产环境中重新安装框架吗?

最佳答案

文件位于服务器上,但最近它表现得很烦躁(现在甚至根本无法访问任何文件),因此请始终使用本地故障转移。

对于 .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
        }
    );
}

关于asp.net - ScriptManager EnableCdn - 不适用于 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11949504/

相关文章:

asp.net - 使用 Javascript 设置 ModalPopupExtender "Y"属性

javascript - 获取 ScriptManager.RegisterStartupScript 警报的结果

.net - 可以使 ASP.NET ScriptManager 与 Windows FIPS 安全策略一起使用吗?

c# - 中央服务器上的 asp.net 成员资格

asp.net - 将 MVVM 应用于 ASP.NET

c# - 从 asp :textbox 获取文本

javascript - 删除、替换或禁用动态生成的 ASP.Net js 代码

php - 先解析php再解析asp.net

cookies - 跨 .Net 和 Core 上的子域的 ASP.NET Identity Cookie

asp.net-mvc - 将 Web 表单 ASP.NET 应用程序迁移到 MVC