/// <summary> /// Handles web specific details of context instantiation. /// </summary> protected override IApplicationContext InstantiateContext(IApplicationContext parent, object configContext, string contextName, Type contextType, bool caseSensitive, string[] resources) { HttpConfigurationContext httpConfigurationContext = (HttpConfigurationContext)configContext; // ASP.NET may scavenge it's configuration section cache if memory usage is too high. // Thus a handler may be called more than once for the same context. // Return registered context in this case. if (ContextRegistry.IsContextRegistered(contextName)) { IApplicationContext ctx = ContextRegistry.GetContext(contextName); if (Log.IsDebugEnabled) { Log.Debug( string.Format("web context '{0}' already registered - returning existing instance {1}", contextName, ctx)); } return(ctx); } // for rewriting path during context instantiation string vpath = httpConfigurationContext.VirtualPath; if (!vpath.EndsWith("/")) { vpath = vpath + "/"; } using (new HttpContextSwitch(vpath)) { return (base.InstantiateContext(parent, configContext, contextName, contextType, caseSensitive, resources)); } }
private String GetVirtualPath(Object configContext) { HttpConfigurationContext httpConfigurationContext = (HttpConfigurationContext)configContext; if (httpConfigurationContext != null) { return(httpConfigurationContext.VirtualPath); } return(String.Empty); }
public virtual object Create(Object parent, Object configContextObj, XmlNode section) { // if called through client config don't even load HttpRuntime if (!HandlerBase.IsServerConfiguration(configContextObj)) { return(null); } HttpConfigurationContext configContext = (HttpConfigurationContext)configContextObj; if (HandlerBase.IsPathAtAppLevel(configContext.VirtualPath) == PathLevel.BelowApp) { throw new ConfigurationException( HttpRuntime.FormatResourceString(SR.Cannot_specify_below_app_level, section.Name), section); } HandlerBase.CheckForChildNodes(section); CodeAccessSecurityValues oRet = new CodeAccessSecurityValues(); XmlNode oAttribute = section.Attributes.RemoveNamedItem("level"); if (oAttribute != null) { oRet.level = oAttribute.Value; } else { oRet.level = (parent != null ? ((CodeAccessSecurityValues)parent).level : ""); } oAttribute = section.Attributes.RemoveNamedItem("originUrl"); if (oAttribute != null) { oRet.url = oAttribute.Value; } else { oRet.url = (parent != null ? ((CodeAccessSecurityValues)parent).url : ""); } HandlerBase.CheckForUnrecognizedAttributes(section); oRet.filename = ConfigurationException.GetXmlNodeFilename(section); oRet.lineNumber = ConfigurationException.GetXmlNodeLineNumber(section); return(oRet); }
void ProcessWsdlHelpGenerator(XmlNode child, object configContext, WebServicesConfiguration config) { string href = null; XmlNode attribute = HandlerBase.GetAndRemoveRequiredStringAttribute(child, "href", ref href); // If we're not running in the context of a web application then skip this setting. HttpConfigurationContext httpConfigContext = configContext as HttpConfigurationContext; if (httpConfigContext == null) { return; } if (href == null) { throw new ConfigurationException(Res.GetString(Res.Missing_required_attribute, attribute, child.Name), child); } if (href.Length == 0) { return; } HandlerBase.CheckForChildNodes(child); HttpContext context = HttpContext.Current; // There can be no context in the case of webless test because the client // runs in the same app domain as ASP.NET so we get an httpconfig object but no context. if (context == null) { return; } string virtualPath = httpConfigContext.VirtualPath; string path; bool isMachineConfig = virtualPath == null; // If the help page is not in the web app directory hierarchy (the case // for those specified in machine.config like DefaultWsdlHelpGenerator.aspx) // then we can't construct a true virtual path. This means that certain web // form features that rely on relative paths won't work. if (isMachineConfig) { virtualPath = context.Request.ApplicationPath; } if (virtualPath[virtualPath.Length - 1] != '/') { virtualPath += "/"; } virtualPath += href; if (isMachineConfig) { path = Path.Combine(GetConfigurationDirectory(), href); } else { path = context.Request.MapPath(virtualPath); } config.WsdlHelpGeneratorPath = path; config.WsdlHelpGeneratorVirtualPath = virtualPath; }