Created
May 26, 2015 18:24
-
-
Save DamianEdwards/baeae33b818145c332b0 to your computer and use it in GitHub Desktop.
Control the CDN paths for ASP.NET 4.x scripts via the ScriptManager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
using System.Web; | |
using System.Web.UI; | |
namespace WebApplication34 | |
{ | |
public class Global : HttpApplication | |
{ | |
void Application_Start(object sender, EventArgs e) | |
{ | |
AddScriptMapping("WebForms.js", typeof(Page).Assembly, "window.WebForm_SetElementY"); | |
AddScriptMapping("WebUIValidation.js", typeof(Page).Assembly, "window.ValidationSummaryOnSubmit"); | |
AddScriptMapping("MenuStandards.js", typeof(Page).Assembly, "window.Sys && window.Sys.WebForms && window.Sys.WebForms.Menu"); | |
AddScriptMapping("Menu.js", typeof(Page).Assembly, "window.Menu_ClearInterval"); | |
AddScriptMapping("Focus.js", typeof(Page).Assembly, "window.WebForm_FindFirstFocusableChild"); | |
AddScriptMapping("GridView.js", typeof(Page).Assembly, "window.GridView"); | |
AddScriptMapping("DetailsView.js", typeof(Page).Assembly, "window.DetailsView"); | |
AddScriptMapping("TreeView.js", typeof(Page).Assembly, "window.TreeView_UnhoverNode"); | |
AddScriptMapping("WebParts.js", typeof(Page).Assembly, "window.WebPartManager_SubmitPage"); | |
AddScriptMapping("SmartNav.js", typeof(Page).Assembly, "window.__smartNav"); | |
AddScriptMapping("MicrosoftAjax.js", typeof(ScriptManager).Assembly, "window.Sys && Sys._Application && Sys.Observer"); | |
AddScriptMapping("MicrosoftAjaxCore.js", typeof(ScriptManager).Assembly, "window.Type && Sys.Observer"); | |
AddScriptMapping("MicrosoftAjaxGlobalization.js", typeof(ScriptManager).Assembly, "window.Sys && Sys.CultureInfo"); | |
AddScriptMapping("MicrosoftAjaxSerialization.js", typeof(ScriptManager).Assembly, "window.Sys && Sys.Serialization"); | |
AddScriptMapping("MicrosoftAjaxComponentModel.js", typeof(ScriptManager).Assembly, "window.Sys && Sys.CommandEventArgs"); | |
AddScriptMapping("MicrosoftAjaxNetwork.js", typeof(ScriptManager).Assembly, "window.Sys && Sys.Net && Sys.Net.WebRequestExecutor"); | |
AddScriptMapping("MicrosoftAjaxHistory.js", typeof(ScriptManager).Assembly, "window.Sys && Sys.HistoryEventArgs"); | |
AddScriptMapping("MicrosoftAjaxWebServices.js", typeof(ScriptManager).Assembly, "window.Sys && Sys.Net && Sys.Net.WebServiceProxy"); | |
AddScriptMapping("MicrosoftAjaxTimer.js", typeof(ScriptManager).Assembly, "window.Sys && Sys.UI && Sys.UI._Timer"); | |
AddScriptMapping("MicrosoftAjaxWebForms.js", typeof(ScriptManager).Assembly, "window.Sys && Sys.WebForms"); | |
AddScriptMapping("MicrosoftAjaxApplicationServices.js", typeof(ScriptManager).Assembly, "window.Sys && Sys.Services"); | |
} | |
private static readonly string CDN_PATH_PREFIX = "http://ajax.aspnetcdn.com/ajax/4.5.1/1/"; | |
private static void AddScriptMapping(string name, Assembly assembly, string loadSuccessExpression) | |
{ | |
ScriptManager.ScriptResourceMapping.AddDefinition(name, new ScriptResourceDefinition | |
{ | |
ResourceName = name, | |
ResourceAssembly = assembly, | |
CdnPath = CDN_PATH_PREFIX + name, | |
LoadSuccessExpression = loadSuccessExpression, | |
CdnSupportsSecureConnection = true | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment