/* Work with multiple virtual paths */ public static string Combine(string basePath, string relativePath) { VirtualPath virtualPath = VirtualPath.Combine(VirtualPath.CreateNonRelative(basePath), VirtualPath.Create(relativePath)); return(virtualPath.VirtualPathStringWhicheverAvailable); }
// helper method to convert an XmlNode to a SiteMapNode private SiteMapNode ConvertFromXmlNode(Queue queue) { SiteMapNode rootNode = null; while (true) { if (queue.Count == 0) { return(rootNode); } SiteMapNode parentNode = (SiteMapNode)queue.Dequeue(); XmlNode xmlNode = (XmlNode)queue.Dequeue(); SiteMapNode node = null; if (!_siteMapNodeName.Equals(xmlNode.Name)) { throw new ConfigurationErrorsException( SR.GetString(SR.XmlSiteMapProvider_Only_SiteMapNode_Allowed), xmlNode); } string providerName = null; HandlerBase.GetAndRemoveNonEmptyStringAttribute(xmlNode, _providerAttribute, ref providerName); // If the siteMapNode references another provider if (providerName != null) { node = GetNodeFromProvider(providerName); // No other attributes or child nodes are allowed on a provider node. HandlerBase.CheckForUnrecognizedAttributes(xmlNode); HandlerBase.CheckForNonCommentChildNodes(xmlNode); } else { string siteMapFile = null; HandlerBase.GetAndRemoveNonEmptyStringAttribute(xmlNode, _siteMapFileAttribute, ref siteMapFile); if (siteMapFile != null) { node = GetNodeFromSiteMapFile(xmlNode, VirtualPath.Create(siteMapFile)); } else { node = GetNodeFromXmlNode(xmlNode, queue); } } AddNodeInternal(node, parentNode, xmlNode); if (rootNode == null) { rootNode = node; } } }
public void TransferRequest(string path, bool preserveForm, string method, NameValueCollection headers) { if (!HttpRuntime.UseIntegratedPipeline) { throw new PlatformNotSupportedException(System.Web.SR.GetString("Requires_Iis_Integrated_Mode")); } if (this._context == null) { throw new HttpException(System.Web.SR.GetString("Server_not_available")); } if (path == null) { throw new ArgumentNullException("path"); } IIS7WorkerRequest workerRequest = this._context.WorkerRequest as IIS7WorkerRequest; HttpRequest request = this._context.Request; HttpResponse response = this._context.Response; if (workerRequest == null) { throw new HttpException(System.Web.SR.GetString("Server_not_available")); } path = response.RemoveAppPathModifier(path); string queryString = null; int index = path.IndexOf('?'); if (index >= 0) { queryString = (index < (path.Length - 1)) ? path.Substring(index + 1) : string.Empty; path = path.Substring(0, index); } if (!UrlPath.IsValidVirtualPathWithoutProtocol(path)) { throw new ArgumentException(System.Web.SR.GetString("Invalid_path_for_child_request", new object[] { path })); } VirtualPath path2 = request.FilePathObject.Combine(VirtualPath.Create(path)); bool preserveUser = true; workerRequest.ScheduleExecuteUrl(path2.VirtualPathString, queryString, method, preserveForm, preserveForm ? request.EntityBody : null, headers, preserveUser); this._context.ApplicationInstance.EnsureReleaseState(); this._context.ApplicationInstance.CompleteRequest(); }
private SiteMapNode ConvertFromXmlNode(Queue queue) { SiteMapNode node = null; while (queue.Count != 0) { SiteMapNode parentNode = (SiteMapNode)queue.Dequeue(); XmlNode node3 = (XmlNode)queue.Dequeue(); SiteMapNode nodeFromProvider = null; if (!"siteMapNode".Equals(node3.Name)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("XmlSiteMapProvider_Only_SiteMapNode_Allowed"), node3); } string val = null; System.Web.Configuration.HandlerBase.GetAndRemoveNonEmptyStringAttribute(node3, "provider", ref val); if (val != null) { nodeFromProvider = this.GetNodeFromProvider(val); System.Web.Configuration.HandlerBase.CheckForUnrecognizedAttributes(node3); System.Web.Configuration.HandlerBase.CheckForNonCommentChildNodes(node3); } else { string str2 = null; System.Web.Configuration.HandlerBase.GetAndRemoveNonEmptyStringAttribute(node3, "siteMapFile", ref str2); if (str2 != null) { nodeFromProvider = this.GetNodeFromSiteMapFile(node3, VirtualPath.Create(str2)); } else { nodeFromProvider = this.GetNodeFromXmlNode(node3, queue); } } this.AddNodeInternal(nodeFromProvider, parentNode, node3); if (node == null) { node = nodeFromProvider; } } return(node); }
private VirtualPath CreateVirtualPathFromUrl(string url) { if (String.IsNullOrEmpty(url)) { return(null); } if (!UrlPath.IsValidVirtualPathWithoutProtocol(url)) { return(null); } if (UrlPath.IsAbsolutePhysicalPath(url)) { return(null); } // Do not generate the virtualPath class at designtime. if (HttpRuntime.AppDomainAppVirtualPath == null) { return(null); } if (UrlPath.IsRelativeUrl(url) && !UrlPath.IsAppRelativePath(url)) { url = UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, url); } // Remove the query string from url so the path can be validated by Authorization module. int queryStringIndex = url.IndexOf('?'); if (queryStringIndex != -1) { url = url.Substring(0, queryStringIndex); } return(VirtualPath.Create(url, VirtualPathOptions.AllowAbsolutePath | VirtualPathOptions.AllowAppRelativePath)); }
internal VirtualPath GetFilePathObject() { // Don't allow malformed paths for security reasons return(VirtualPath.Create(GetFilePath(), VirtualPathOptions.AllowAbsolutePath | VirtualPathOptions.AllowNull)); }
public void Execute(string path, TextWriter writer, bool preserveForm) { if (this._context == null) { throw new HttpException(System.Web.SR.GetString("Server_not_available")); } if (path == null) { throw new ArgumentNullException("path"); } string queryStringOverride = null; HttpRequest request = this._context.Request; path = this._context.Response.RemoveAppPathModifier(path); int index = path.IndexOf('?'); if (index >= 0) { queryStringOverride = path.Substring(index + 1); path = path.Substring(0, index); } if (!UrlPath.IsValidVirtualPathWithoutProtocol(path)) { throw new ArgumentException(System.Web.SR.GetString("Invalid_path_for_child_request", new object[] { path })); } VirtualPath virtualPath = VirtualPath.Create(path); IHttpHandler handler = null; string filename = request.MapPath(virtualPath); VirtualPath path3 = request.FilePathObject.Combine(virtualPath); InternalSecurityPermissions.FileReadAccess(filename).Demand(); if (HttpRuntime.IsLegacyCas) { InternalSecurityPermissions.Unrestricted.Assert(); } try { if (StringUtil.StringEndsWith(virtualPath.VirtualPathString, '.')) { throw new HttpException(0x194, string.Empty); } bool useAppConfig = !path3.IsWithinAppRoot; using (new DisposableHttpContextWrapper(this._context)) { try { this._context.ServerExecuteDepth++; if (this._context.WorkerRequest is IIS7WorkerRequest) { handler = this._context.ApplicationInstance.MapIntegratedHttpHandler(this._context, request.RequestType, path3, filename, useAppConfig, true); } else { handler = this._context.ApplicationInstance.MapHttpHandler(this._context, request.RequestType, path3, filename, useAppConfig); } } finally { this._context.ServerExecuteDepth--; } } } catch (Exception exception) { if (exception is HttpException) { int httpCode = ((HttpException)exception).GetHttpCode(); if ((httpCode != 500) && (httpCode != 0x194)) { exception = null; } } throw new HttpException(System.Web.SR.GetString("Error_executing_child_request_for_path", new object[] { path }), exception); } this.ExecuteInternal(handler, writer, preserveForm, true, virtualPath, path3, filename, null, queryStringOverride); }
public static bool IsAppRelative(string virtualPath) { VirtualPath virtualPathObject = VirtualPath.Create(virtualPath); return(virtualPathObject.VirtualPathStringIfAvailable == null); }
/* Discover virtual path type */ public static bool IsAbsolute(string virtualPath) { VirtualPath virtualPathObject = VirtualPath.Create(virtualPath); return(!virtualPathObject.IsRelative && virtualPathObject.VirtualPathStringIfAvailable != null); }
public static string GetExtension(string virtualPath) { VirtualPath virtualPathObject = VirtualPath.Create(virtualPath); return(virtualPathObject.Extension); }
internal VirtualPath GetFilePathObject() { return(VirtualPath.Create(this.GetFilePath(), VirtualPathOptions.AllowAbsolutePath | VirtualPathOptions.AllowNull)); }
public static bool IsAppRelative(string virtualPath) { return(VirtualPath.Create(virtualPath).VirtualPathStringIfAvailable == null); }
public static bool IsAbsolute(string virtualPath) { VirtualPath path = VirtualPath.Create(virtualPath); return(!path.IsRelative && (path.VirtualPathStringIfAvailable != null)); }
public static string GetExtension(string virtualPath) { return(VirtualPath.Create(virtualPath).Extension); }