internal static string GetWebResourceUrlInternal(Assembly assembly, string resourceName, bool htmlEncoded, bool forSubstitution, IScriptManager scriptManager) { bool isSecureConnection; EnsureHandlerExistenceChecked(); if (!_handlerExists) { throw new InvalidOperationException(System.Web.SR.GetString("AssemblyResourceLoader_HandlerNotRegistered")); } Assembly resourceAssembly = assembly; string str = resourceName; bool enableCdn = false; bool debuggingEnabled = false; if (scriptManager != null) { enableCdn = scriptManager.EnableCdn; debuggingEnabled = scriptManager.IsDebuggingEnabled; isSecureConnection = scriptManager.IsSecureConnection; } else { isSecureConnection = ((HttpContext.Current != null) && (HttpContext.Current.Request != null)) && HttpContext.Current.Request.IsSecureConnection; } int num = CreateWebResourceUrlCacheKey(assembly, resourceName, htmlEncoded, forSubstitution, enableCdn, debuggingEnabled, isSecureConnection); string s = (string)_urlCache[num]; if (s == null) { IScriptResourceDefinition definition = null; if (ClientScriptManager._scriptResourceMapping != null) { definition = ClientScriptManager._scriptResourceMapping.GetDefinition(resourceName, assembly); if (definition != null) { if (!string.IsNullOrEmpty(definition.ResourceName)) { str = definition.ResourceName; } if (definition.ResourceAssembly != null) { resourceAssembly = definition.ResourceAssembly; } } } string debugPath = null; if (definition != null) { if (enableCdn) { if (debuggingEnabled) { debugPath = isSecureConnection ? definition.CdnDebugPathSecureConnection : definition.CdnDebugPath; if (string.IsNullOrEmpty(debugPath)) { debugPath = definition.DebugPath; if (string.IsNullOrEmpty(debugPath)) { if (!isSecureConnection || string.IsNullOrEmpty(definition.CdnDebugPath)) { debugPath = GetCdnPath(str, resourceAssembly, isSecureConnection); } if (string.IsNullOrEmpty(debugPath)) { debugPath = definition.Path; } } } } else { debugPath = isSecureConnection ? definition.CdnPathSecureConnection : definition.CdnPath; if (string.IsNullOrEmpty(debugPath)) { if (!isSecureConnection || string.IsNullOrEmpty(definition.CdnPath)) { debugPath = GetCdnPath(str, resourceAssembly, isSecureConnection); } if (string.IsNullOrEmpty(debugPath)) { debugPath = definition.Path; } } } } else if (debuggingEnabled) { debugPath = definition.DebugPath; if (string.IsNullOrEmpty(debugPath)) { debugPath = definition.Path; } } else { debugPath = definition.Path; } } else if (enableCdn) { debugPath = GetCdnPath(str, resourceAssembly, isSecureConnection); } if (!string.IsNullOrEmpty(debugPath)) { if (UrlPath.IsAppRelativePath(debugPath)) { if (_applicationRootPath == null) { s = VirtualPathUtility.ToAbsolute(debugPath); } else { s = VirtualPathUtility.ToAbsolute(debugPath, _applicationRootPath); } } else { s = debugPath; } if (htmlEncoded) { s = HttpUtility.HtmlEncode(s); } } else { string str4; Pair assemblyInfo = GetAssemblyInfo(resourceAssembly); AssemblyName first = (AssemblyName)assemblyInfo.First; long second = (long)assemblyInfo.Second; string str5 = first.Version.ToString(); if (resourceAssembly.GlobalAssemblyCache) { if (resourceAssembly == HttpContext.SystemWebAssembly) { str4 = "s"; } else { StringBuilder builder = new StringBuilder(); builder.Append('f'); builder.Append(first.Name); builder.Append(','); builder.Append(str5); builder.Append(','); if (first.CultureInfo != null) { builder.Append(first.CultureInfo.ToString()); } builder.Append(','); byte[] publicKeyToken = first.GetPublicKeyToken(); for (int i = 0; i < publicKeyToken.Length; i++) { builder.Append(publicKeyToken[i].ToString("x2", CultureInfo.InvariantCulture)); } str4 = builder.ToString(); } } else { str4 = "p" + first.Name; } s = FormatWebResourceUrl(str4, str, second, htmlEncoded); if (!forSubstitution && (HttpRuntime.AppDomainAppVirtualPathString != null)) { s = UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, s); } } _urlCache[num] = s; } return(s); }
internal static string GetWebResourceUrlInternal(Assembly assembly, string resourceName, bool htmlEncoded, bool forSubstitution, IScriptManager scriptManager, bool enableCdn) { // When this url is being inserted as a substitution in another resource, // it should just be "WebResource.axd?d=..." since the resource is already coming // from the app root (i.e. no need for a full absolute /app/WebResource.axd). // Otherwise we must return a path that is absolute (starts with '/') or // a full absolute uri (http://..) as in the case of a CDN Path. EnsureHandlerExistenceChecked(); if (!_handlerExists) { throw new InvalidOperationException(SR.GetString(SR.AssemblyResourceLoader_HandlerNotRegistered)); } Assembly effectiveAssembly = assembly; string effectiveResourceName = resourceName; bool debuggingEnabled = false; bool secureConnection; if (scriptManager != null) { debuggingEnabled = scriptManager.IsDebuggingEnabled; secureConnection = scriptManager.IsSecureConnection; } else { secureConnection = ((HttpContext.Current != null) && (HttpContext.Current.Request != null) && HttpContext.Current.Request.IsSecureConnection); debuggingEnabled = (HttpContext.Current != null) && HttpContext.Current.IsDebuggingEnabled; } int urlCacheKey = CreateWebResourceUrlCacheKey(assembly, resourceName, htmlEncoded, forSubstitution, enableCdn, debuggingEnabled, secureConnection); string url = (string)_urlCache[urlCacheKey]; if (url == null) { IScriptResourceDefinition definition = null; if (ClientScriptManager._scriptResourceMapping != null) { definition = ClientScriptManager._scriptResourceMapping.GetDefinition(resourceName, assembly); if (definition != null) { if (!String.IsNullOrEmpty(definition.ResourceName)) { effectiveResourceName = definition.ResourceName; } if (definition.ResourceAssembly != null) { effectiveAssembly = definition.ResourceAssembly; } } } string path = null; // if a resource mapping exists, take it's settings into consideration // it might supply a path or a cdnpath. if (definition != null) { if (enableCdn) { // Winner is first path defined, falling back on the effectiveResourceName/Assembly // Debug Mode : d.CdnDebugPath, d.DebugPath, *wra.CdnPath, d.Path // Release Mode: d.CdnPath , *wra.CdnPath, d.Path // * the WebResourceAttribute corresponding to the resource defined in the definition, not the // the original resource. // Also, if the definition has a CdnPath but it cannot be converted to a secure one during https, // the WRA's CdnPath is not considered. if (debuggingEnabled) { path = secureConnection ? definition.CdnDebugPathSecureConnection : definition.CdnDebugPath; if (String.IsNullOrEmpty(path)) { path = definition.DebugPath; if (String.IsNullOrEmpty(path)) { // Get CDN Path from the redirected resource name/assembly, not the original one, // but not if this is a secure connection and the only reason we didn't use the definition // cdn path is because it doesnt support secure connections. if (!secureConnection || String.IsNullOrEmpty(definition.CdnDebugPath)) { path = GetCdnPath(effectiveResourceName, effectiveAssembly, secureConnection); } if (String.IsNullOrEmpty(path)) { path = definition.Path; } } } } else { path = secureConnection ? definition.CdnPathSecureConnection : definition.CdnPath; if (String.IsNullOrEmpty(path)) { // Get CDN Path from the redirected resource name/assembly, not the original one // but not if this is a secure connection and the only reason we didn't use the definition // cdn path is because it doesnt support secure connections. if (!secureConnection || String.IsNullOrEmpty(definition.CdnPath)) { path = GetCdnPath(effectiveResourceName, effectiveAssembly, secureConnection); } if (String.IsNullOrEmpty(path)) { path = definition.Path; } } } } // cdn else { // Winner is first path defined, falling back on the effectiveResourceName/Assembly // Debug Mode : d.DebugPath, d.Path // Release Mode: d.Path if (debuggingEnabled) { path = definition.DebugPath; if (String.IsNullOrEmpty(path)) { path = definition.Path; } } else { path = definition.Path; } } } // does not have definition else if (enableCdn) { path = GetCdnPath(effectiveResourceName, effectiveAssembly, secureConnection); } if (!String.IsNullOrEmpty(path)) { // assembly based resource has been overridden by a path, // whether that be a CDN Path or a definition.Path or DebugPath. // We must return a path that is absolute (starts with '/') or // a full absolute uri (http://..) as in the case of a CDN Path. // An overridden Path that is not a CDN Path is required to be absolute // or app relative. if (UrlPath.IsAppRelativePath(path)) { // expand ~/. If it is rooted (/) or an absolute uri, no conversion needed if (_applicationRootPath == null) { url = VirtualPathUtility.ToAbsolute(path); } else { url = VirtualPathUtility.ToAbsolute(path, _applicationRootPath); } } else { // must be a full uri or already rooted. url = path; } if (htmlEncoded) { url = HttpUtility.HtmlEncode(url); } } else { string urlAssemblyName; Pair assemblyInfo = GetAssemblyInfo(effectiveAssembly); AssemblyName assemblyName = (AssemblyName)assemblyInfo.First; long assemblyDate = (long)assemblyInfo.Second; string assemblyVersion = assemblyName.Version.ToString(); if (effectiveAssembly.GlobalAssemblyCache) { // If the assembly is in the GAC, we need to store a full name to load the assembly later if (effectiveAssembly == HttpContext.SystemWebAssembly) { urlAssemblyName = "s"; } else { // Pack the necessary values into a more compact format than FullName StringBuilder builder = new StringBuilder(); builder.Append('f'); builder.Append(assemblyName.Name); builder.Append(','); builder.Append(assemblyVersion); builder.Append(','); if (assemblyName.CultureInfo != null) { builder.Append(assemblyName.CultureInfo.ToString()); } builder.Append(','); byte[] token = assemblyName.GetPublicKeyToken(); for (int i = 0; i < token.Length; i++) { builder.Append(token[i].ToString("x2", CultureInfo.InvariantCulture)); } urlAssemblyName = builder.ToString(); } } else { // Otherwise, we can just use a partial name urlAssemblyName = "p" + assemblyName.Name; } url = FormatWebResourceUrl(urlAssemblyName, effectiveResourceName, assemblyDate, htmlEncoded); if (!forSubstitution && (HttpRuntime.AppDomainAppVirtualPathString != null)) { // When this url is being inserted as a substitution in another resource, // it should just be "WebResource.axd?d=..." since the resource is already coming // from the app root (i.e. no need for a full absolute /app/WebResource.axd). url = UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, url); } } _urlCache[urlCacheKey] = url; } return(url); }