在ASP.NET Web Forms 4.5中捆绑JQuery

Cle*_*ud8 5 asp.net jquery webforms visual-studio-2012 bundling-and-minification

我使用Visual Studio 2012和内置模板(在Add - > New Project下)创建一个全新的ASP.NET Web Forms Web应用程序项目.在默认情况下提供的Site.Master页面中,我看到了一些针对JQuery的标记,它包含在下面.

考虑到以下标记,ASP.NET如何确定包含JQuery所需的路径?

<asp:ScriptManager runat="server">
    <Scripts>
        <%--Framework Scripts--%>
        <asp:ScriptReference Name="MsAjaxBundle" />
        <asp:ScriptReference Name="jquery" />
        <asp:ScriptReference Name="jquery.ui.combined" />
        <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="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.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>
</asp:ScriptManager>
Run Code Online (Sandbox Code Playgroud)

我没有看到任何配置文件或代码将jquery解析为"〜/ Scripts/jquery-1.7.1.js".我看到一个packages.config文件,但它没有明确描述必须以某种方式计算的路径.

有谁知道如何在运行时解决JQuery的javascript文件的路径?

Hao*_*ung 4

在 Microsoft.ScriptManager.WebForms PreAppStartCode 内部,它具有:

        System.Web.UI.ScriptManager.ScriptResourceMapping.AddDefinition("WebFormsBundle", new ScriptResourceDefinition
        {
            Path = "~/bundles/WebFormsJs",
            CdnPath = "http://ajax.aspnetcdn.com/ajax/4.5/6/WebFormsBundle.js",
            LoadSuccessExpression="window.WebForm_PostBackOptions",
            CdnSupportsSecureConnection = true
        });
Run Code Online (Sandbox Code Playgroud)

这是连接到脚本引用中的声明的内容:

<asp:ScriptReference Name="WebFormsBundle" />

并且还会进行重复数据删除,因为 ScriptReference 路径与捆绑包内的文件路径相同,这些文件应在 BundleConfig.cs 内注册

  • 对于任何想知道它在哪里的人,如果您在“Start()”方法中反映“Microsoft.ScriptManager.WebForms.dll”,它就会出现。 (3认同)