如何摆脱不需要的脚本标签 [英] How to get rid of unwanted script tags

查看:77
本文介绍了如何摆脱不需要的脚本标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我们的网络表格中插入了三个不需要的和脚本标签:



Hi there,

There are three unwanted and script tags being inserted into our webforms:

Loading failed for the <script> with source "https://localhost:44304/Scripts/WebForms/MsAjax/MicrosoftAjax.js".
Loading failed for the <script> with source "https://localhost:44304/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js".
Loading failed for the <script> with source "https://localhost:44304/Scripts/jquery-3.3.1.js".



我无法弄清楚它们的生成位置。



该网站确实同时使用了jquery和MsAjax,但它们被捆绑/引用(BundleConfig.cs):


I have not been able to figure out where they are being generated.

The site does use both jquery and MsAjax, but the are being included/referenced in a bundle (BundleConfig.cs):

bundles.Add(new ScriptBundle("~/bundles/MsAjaxJs").Include(
    "~/Recursos/Scripts/WebForms/MsAjax/MicrosoftAjax.js",
    "~/Recursos/Scripts/WebForms/MsAjax/MicrosoftAjaxApplicationServices.js",
    "~/Recursos/Scripts/WebForms/MsAjax/MicrosoftAjaxTimer.js",
    "~/Recursos/Scripts/WebForms/MsAjax/MicrosoftAjaxWebForms.js"));

bundles.Add(new ScriptBundle("~/bundles/jQuery").Include(
    "~/Recursos/Scripts/jquery-3.3.1.min.js"
    , "~/Recursos/Scripts/jquery-ui-1.12.1.js"
    ));



这是我们的Global.asax(摘录):


Here's our Global.asax (extract):

protected void Application_Start(object sender, EventArgs e)
        {
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }



这是我们的母版页(摘录):


And here's our Master Page (extract):

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



正如您所看到的,我们项目中所述文件的实际路径实际上是:

〜/ Recursos /脚本/ jquery-3.3.1.min.js



〜/ Recursos / Scripts / WebForms / ...



此外,所说的捆绑包正确加载:


As you can see, the actual path in our project for said files is in fact:
"~/Recursos/Scripts/jquery-3.3.1.min.js"
and
"~/Recursos/Scripts/WebForms/..."

Moreover, said bundles are being correctly loaded:

Status 200 OK https://localhost:44304/bundles/MsAjaxJs?v=J4joXQqg80Lks57qbGfUAfRLic3bXKGafmR6wE4CFtc1
Status 200 OK https://localhost:44304/bundles/jQuery?v=2zGDWE11e8d2S6KhU5f00BBoMAWCqoXDrlwpjBbHHsE1





我尝试过:



试图在我们的代码中找到指向所述程序集的任何其他引用,无济于事。



非常感谢您的指导。< br $>


谢谢。



U PDATE:(20180508 17:15)

我刚发现那些参考文献来自哪里; ScriptManager对象添加了一些内容。它们驻留在默认的ScriptResourceMapping定义中。



我仍​​然忽略了为什么我们在这个项目中得到这个行为而不是其他也实现ScriptManager的行为。



我成功修改了两个MicrosoftAjax ...定义调试路径,但是当弄乱jquery时,我得到一个Webform UnobtrusiveValidationMode消息,我将继续试图弄清楚。



What I have tried:

Tried to locate, to no avail, any other reference in our code pointing to said assemblies.

Your guidance is much appreciated.

Thanks.

UPDATE: (20180508 17:15)
I just discovered where those references come from; there are being added by the ScriptManager object. They reside in its default ScriptResourceMapping definitions.

I still ignore why we get this "behavior" in this project and not other which also implement a ScriptManager.

I successfully modified the two MicrosoftAjax... definition debug paths, but when messing with jquery, I get a "Webform UnobtrusiveValidationMode" message, which I will continue to try to figure out.

推荐答案

好的,我会发布我能够做的事情,以防它帮助其他人。但是,请注意!这整个事情闻起来像是一种解决方案,而不是真正的解决方案。



第一件事

这些不需要的标签是由我们母版页中实现的ScriptManager对象编写的。



默认情况下它们没有被加载,因为我们选择将我们的脚本,css和其他资源重定位到非标准文件夹;这可能是其他项目没有提出上述问题的原因。


2nd Global.asax

在Application_Start中方法,我们编辑ScriptManager的默认ScriptResourceMapping定义,将所述对象指向我们的自定义资源路径:



Ok, I 'll post what I was able to do in case it helps someone else. But, be advised!, this whole thing smells like a work-around rather than a real solution.

1st things first:
Those "unwanted" tags were being written by the ScriptManager object implemented in our Master Page.

They were not being loaded by default, because we chose to relocate our scripts, css, and other resources to a non standard folder; that's probably why other projects do not present said issue.

2nd Global.asax:
In the Application_Start method, is where we edited the ScriptManager's default ScriptResourceMapping definitions to point said objects to our custom resource path:

        protected void Application_Start(object sender, EventArgs e)
        {
            ScriptManager.ScriptResourceMapping.GetDefinition("jquery").DebugPath = "~/Recursos/Scripts/jquery-3.3.1.js";

ScriptManager.ScriptResourceMapping.GetDefinition("MicrosoftAjax.js").DebugPath = "~/Recursos/Scripts/Webforms/MSAjax/MicrosoftAjax.js";

ScriptManager.ScriptResourceMapping.GetDefinition("MicrosoftAjaxWebForms.js").DebugPath = "~/Recursos/Scripts/Webforms/MSAjax/MicrosoftAjaxWebForms.js";

            BundleConfig.RegisterBundles(BundleTable.Bundles);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }





最后是Web.config

要解决我们添加了WebForms UnobtrusiveValidationMode问题,以及此处 web.config文件的以下条目:



Finally Web.config:
To resolve the "WebForms UnobtrusiveValidationMode" issue, and as seen here, we added the following entry to the web.config file:

<appSettings>
      <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
    </appSettings>





现在我们可以运行我们的网络应用程序而不会出现意外的遗失文件,或者jquery的问题。



干杯!



Now we are able to run our web application without the undesired "missing files", or issues with jquery.

Cheers!


这篇关于如何摆脱不需要的脚本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆