【问题标题】:How to find the source of a rogue script call in WebForms如何在 WebForms 中找到恶意脚本调用的来源
【发布时间】:2023-04-05 23:21:02
【问题描述】:

我正在寻找一个 WebForms 项目中的一个奇怪错误,在该项目中我找不到第二个 jQuery 参考的来源。

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
        "~/Scripts/jquery-1.10.2.min.js",
        //additional entries omitted
    ));

现在这个包在我的母版页文件中被调用:

<asp:PlaceHolder runat="server">
    <%: Scripts.Render("~/bundles/jquery") %>
    <%: Styles.Render("...") %>
</asp:PlaceHolder>

只要用户停留在网页的根文件夹 (www.domain.com/page),evertyhing 就可以正常工作。不幸的是,当用户被重定向到位于子文件夹 (www.domain.com/subfolder/someotherpage) 中的 aspx 页面时,会出现以下错误:

Failed to load resource: the server responded with a status of 404 (Not Found) http://localhost:53078/Scripts/jquery-1.10.2.js

我已经搜索了整个解决方案,但找不到它的来源。

查看渲染的源代码我看到了这个:

<body>
   <script src="../Scripts/jquery-1.10.2.js" type="text/javascript"></script>
</body>

现在这看起来不像由捆绑渲染的脚本标签,它们位于头部。给定脚本标签的位置,这应该来自母版页文件,但我不能指望它:

<head runat="server">
    <asp:PlaceHolder runat="server">
        <%: Scripts.Render("~/bundles/jquery") %>
        <%: Styles.Render("~/bundles/Stylesheets") %>
    </asp:PlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager runat="server" EnableEmbeddedjQuery="false">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryExternal.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryPlugins.js" />
            </Scripts>
        </telerik:RadScriptManager>

    <%: Scripts.Render("~/bundles/UiEffects") %>
</body>

在您提出建议之前:我已尝试将 RadScriptManager 替换为原版 asp:ScriptManager,但无济于事。

是否可以确定脚本引用源自 asp.net Web 项目中的哪一行代码,以便我可以消除它?

【问题讨论】:

    标签: asp.net telerik scriptmanager asp.net-bundling


    【解决方案1】:

    由于没有明显的对 jQuery-1.10.2.js 的纯文本引用,它必须是 Telerik 中的错误或引用的程序集。

    我没有检查已安装的 Nuget 包。已经安装了一个,它会自动向 ScriptManager 注册 jQuery:

    http://www.nuget.org/packages/AspNet.ScriptManager.jQuery/1.10.2

    如果你已经安装了这个,你不能再引用jQuery,否则你可能会遇到$(...).functionName() is not a function 错误。

    所以,这个问题有两种可能的解决方案:

    1. 重新安装此包/更新此包并删除母版页文件中对 jQuery 的所有其他引用或
    2. 使用uninstall-package AspNet.ScriptManager.jQuery -project xxx 删除此 NuGet 包

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多