0
votes

How/where does asp.net populate System.Web.UI.ScriptManager.ScriptResourceMapping? When I debug an untouched empty ASP.Net webforms project (targeting .NET 4.6.1 if it matters) and set a breakpoint at the beginning of Application_Start(object sender, EventArgs e), there are already 15 definitions:

Screenshot of definitions

The call stack doesn't tell me what code was run before this (just says [External Code]) and the only place in the entire solution that references ScriptManager is in BundleConfig#RegisterBundles() which is called after my break point and only adds a single definition.

The reason I ask is I was recently brought in to troubleshoot another project and I found that for some reason, it had a nearly empty ScriptResourceMapping and I ended up copying the values from the debugger of a template project and manually adding them in code in the malfunctioning project. I just want to better understand what went wrong.

Again, this question is about how a totally new webform project populates the ScriptResourceMappings. Here's the packages.conf of the project. Notice there are a few ScriptManager packages. Perhaps it is something in these packages that loads definitions into ScriptManager.

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.4.1.9004" targetFramework="net461" />
  <package id="AspNet.ScriptManager.bootstrap" version="3.0.0" targetFramework="net461" />
  <package id="AspNet.ScriptManager.jQuery" version="1.10.2" targetFramework="net461" />
  <package id="bootstrap" version="3.0.0" targetFramework="net461" />
  <package id="jQuery" version="1.10.2" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights" version="2.2.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.0.6" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.2.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.2.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.Web" version="2.2.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.2.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.2.0" targetFramework="net461" />
  <package id="Microsoft.AspNet.FriendlyUrls" version="1.0.2" targetFramework="net461" />
  <package id="Microsoft.AspNet.FriendlyUrls.Core" version="1.0.2" targetFramework="net461" />
  <package id="Microsoft.AspNet.ScriptManager.MSAjax" version="5.0.0" targetFramework="net461" />
  <package id="Microsoft.AspNet.ScriptManager.WebForms" version="5.0.0" targetFramework="net461" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.Web.Optimization.WebForms" version="1.1.3" targetFramework="net461" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.7" targetFramework="net461" />
  <package id="Microsoft.Net.Compilers" version="2.1.0" targetFramework="net461" developmentDependency="true" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net461" />
  <package id="Modernizr" version="2.6.2" targetFramework="net461" />
  <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net461" />
  <package id="Respond" version="1.2.0" targetFramework="net461" />
  <package id="WebGrease" version="1.5.2" targetFramework="net461" />
</packages>
1

1 Answers

0
votes

The ScriptResourceMapping class (System.Web.UI) looks like a dead end.

The ScriptManager class looks more promising. It has a ScriptResourceMapping property. The link below shows how you can create a ScriptResourceDefinition object that can be referenced by a ScriptManager object.

"Add the following code to the Global.asax file in the Application_Start event."

ScriptResourceDefinition myScriptResDef = new ScriptResourceDefinition();
myScriptResDef.Path = "~/Scripts/jquery-1.4.2.min.js";
myScriptResDef.DebugPath = "~/Scripts/jquery-1.4.2.js";
myScriptResDef.CdnPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js";
myScriptResDef.CdnDebugPath = "http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.js";
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", null, myScriptResDef);

then there's a bit more info about adding the scripts element to the script manager.

https://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.scriptresourcemapping(v=vs.110).aspx

I'm guessing that .NET takes care of this in a similar way once it sees the packages file, but I (still) don't know exactly where or when. (On build?) Hth.