public string GetAppPathForPath(string siteID, string path)
        {
            string appPath = _hostingConfigMapPath.GetAppPathForPath(siteID, path);

            if (appPath == null)
            {
                appPath = _iisConfigMapPath.GetAppPathForPath(siteID, path);
            }

            return(appPath);
        }
Пример #2
0
        // IsApplication
        //
        // Given a config Path, is it the Path for an application?
        //
        private bool IsApplication(string configPath)
        {
            VirtualPath appPath;
            string      siteID;
            VirtualPath vpath;

            // Break up into siteID and vpath
            GetSiteIDAndVPathFromConfigPath(configPath, out siteID, out vpath);

            // Retrieve appPath for this
            if (null != _configMapPath2)
            {
                appPath = _configMapPath2.GetAppPathForPath(siteID, vpath);
            }
            else
            {
                appPath = VirtualPath.CreateAllowNull(_configMapPath.GetAppPathForPath(siteID, vpath.VirtualPathString));
            }

            return(appPath == vpath);
        }
        // Not used in runtime because in runtime we have all the siteid, appPath, etc. already.
        static internal void GetConfigPaths(IConfigMapPath configMapPath, WebLevel webLevel, VirtualPath virtualPath, string site, string locationSubPath,
                out VirtualPath appPath, out string appSiteName, out string appSiteID, out string configPath, out string locationConfigPath) {

            appPath = null;
            appSiteName = null;
            appSiteID = null;

            if (webLevel == WebLevel.Machine || virtualPath == null) {
                // Site is meaningless at machine and root web.config level
                // However, we allow a site parameter if the caller is opening
                // a location tag.  See VSWhidbey 548361.
                if (!String.IsNullOrEmpty(site) && String.IsNullOrEmpty(locationSubPath)) {
                    throw ExceptionUtil.ParameterInvalid("site");
                }

                if (webLevel == WebLevel.Machine) {
                    configPath = MachineConfigPath;
                }
                else {
                    configPath = RootWebConfigPath;
                }
            }
            else {
                // Get the site name and ID
                if (!String.IsNullOrEmpty(site)) {
                    configMapPath.ResolveSiteArgument(site, out appSiteName, out appSiteID);

                    if (String.IsNullOrEmpty(appSiteID)) {
                        throw new InvalidOperationException(SR.GetString(SR.Config_failed_to_resolve_site_id, site));
                    }
                }
                else {
                    // If site not supplied, try hosting environment first
                    if (HostingEnvironment.IsHosted) {
                        appSiteName = HostingEnvironment.SiteNameNoDemand;
                        appSiteID = HostingEnvironment.SiteID;
                    }

                    // Rely on defaults if not provided in hosting environment
                    if (String.IsNullOrEmpty(appSiteID)) {
                        configMapPath.GetDefaultSiteNameAndID(out appSiteName, out appSiteID);
                    }

                    Debug.Assert(!String.IsNullOrEmpty(appSiteID), "No appSiteID found when site argument is null");
                }

                configPath = GetConfigPathFromSiteIDAndVPath(appSiteID, virtualPath);
            }

            // get locationConfigPath
            locationConfigPath = null;
            string locationSite = null;
            VirtualPath locationVPath = null;
            if (locationSubPath != null) {
                locationConfigPath = GetConfigPathFromLocationSubPathBasic(configPath, locationSubPath);
                GetSiteIDAndVPathFromConfigPath(locationConfigPath, out locationSite, out locationVPath);

                // If we're at machine or root web.config level and a location path is given,
                // handle the site part of the location path.
                if (String.IsNullOrEmpty(appSiteID) && !String.IsNullOrEmpty(locationSite)) {
                    configMapPath.ResolveSiteArgument(locationSite, out appSiteName, out appSiteID);
                    if (!String.IsNullOrEmpty(appSiteID)) {
                        // Recompose the location config path based on new appSiteID
                        locationConfigPath = GetConfigPathFromSiteIDAndVPath(appSiteID, locationVPath);
                    }
                    else {
                        // If there is no path, then allow the location to be edited,
                        // as we don't need to map elements of the path.
                        if (locationVPath == null || locationVPath.VirtualPathString == "/") {
                            appSiteName = locationSite;
                            appSiteID = locationSite;
                        }
                        // Otherwise, the site argument is ambiguous.
                        else {
                            // 

                            appSiteName = null;
                            appSiteID = null;
                        }
                    }
                }
            }

            // get appPath
            string appPathString = null;
            if (locationVPath != null) {
                appPathString = configMapPath.GetAppPathForPath(appSiteID, locationVPath.VirtualPathString);
            }
            else if (virtualPath != null) {
                appPathString = configMapPath.GetAppPathForPath(appSiteID, virtualPath.VirtualPathString);
            }

            if (appPathString != null) {
                appPath = VirtualPath.Create(appPathString);
            }
        }
 /// <summary>
 /// Gets the virtual-directory name associated with a specific site.
 /// </summary>
 /// <param name="siteID">A unique identifier for the site.</param>
 /// <param name="path">The URL associated with the site.</param>
 /// <returns>
 /// The <paramref name="siteID" /> must be unique. No two sites share the same id. The <paramref name="siteID" /> distinguishes sites that have the same name.
 /// </returns>
 public String GetAppPathForPath(String siteID, String path)
 {
     return(mOriginal.GetAppPathForPath(siteID, path));
 }
Пример #5
0
        // Not used in runtime because in runtime we have all the siteid, appPath, etc. already.
        static internal void GetConfigPaths(IConfigMapPath configMapPath, WebLevel webLevel, VirtualPath virtualPath, string site, string locationSubPath,
                                            out VirtualPath appPath, out string appSiteName, out string appSiteID, out string configPath, out string locationConfigPath)
        {
            appPath     = null;
            appSiteName = null;
            appSiteID   = null;

            if (webLevel == WebLevel.Machine || virtualPath == null)
            {
                // Site is meaningless at machine and root web.config level
                // However, we allow a site parameter if the caller is opening
                // a location tag.  See VSWhidbey 548361.
                if (!String.IsNullOrEmpty(site) && String.IsNullOrEmpty(locationSubPath))
                {
                    throw ExceptionUtil.ParameterInvalid("site");
                }

                if (webLevel == WebLevel.Machine)
                {
                    configPath = MachineConfigPath;
                }
                else
                {
                    configPath = RootWebConfigPath;
                }
            }
            else
            {
                // Get the site name and ID
                if (!String.IsNullOrEmpty(site))
                {
                    configMapPath.ResolveSiteArgument(site, out appSiteName, out appSiteID);

                    if (String.IsNullOrEmpty(appSiteID))
                    {
                        throw new InvalidOperationException(SR.GetString(SR.Config_failed_to_resolve_site_id, site));
                    }
                }
                else
                {
                    // If site not supplied, try hosting environment first
                    if (HostingEnvironment.IsHosted)
                    {
                        appSiteName = HostingEnvironment.SiteNameNoDemand;
                        appSiteID   = HostingEnvironment.SiteID;
                    }

                    // Rely on defaults if not provided in hosting environment
                    if (String.IsNullOrEmpty(appSiteID))
                    {
                        configMapPath.GetDefaultSiteNameAndID(out appSiteName, out appSiteID);
                    }

                    Debug.Assert(!String.IsNullOrEmpty(appSiteID), "No appSiteID found when site argument is null");
                }

                configPath = GetConfigPathFromSiteIDAndVPath(appSiteID, virtualPath);
            }

            // get locationConfigPath
            locationConfigPath = null;
            string      locationSite  = null;
            VirtualPath locationVPath = null;

            if (locationSubPath != null)
            {
                locationConfigPath = GetConfigPathFromLocationSubPathBasic(configPath, locationSubPath);
                GetSiteIDAndVPathFromConfigPath(locationConfigPath, out locationSite, out locationVPath);

                // If we're at machine or root web.config level and a location path is given,
                // handle the site part of the location path.
                if (String.IsNullOrEmpty(appSiteID) && !String.IsNullOrEmpty(locationSite))
                {
                    configMapPath.ResolveSiteArgument(locationSite, out appSiteName, out appSiteID);
                    if (!String.IsNullOrEmpty(appSiteID))
                    {
                        // Recompose the location config path based on new appSiteID
                        locationConfigPath = GetConfigPathFromSiteIDAndVPath(appSiteID, locationVPath);
                    }
                    else
                    {
                        // If there is no path, then allow the location to be edited,
                        // as we don't need to map elements of the path.
                        if (locationVPath == null || locationVPath.VirtualPathString == "/")
                        {
                            appSiteName = locationSite;
                            appSiteID   = locationSite;
                        }
                        // Otherwise, the site argument is ambiguous.
                        else
                        {
                            //

                            appSiteName = null;
                            appSiteID   = null;
                        }
                    }
                }
            }

            // get appPath
            string appPathString = null;

            if (locationVPath != null)
            {
                appPathString = configMapPath.GetAppPathForPath(appSiteID, locationVPath.VirtualPathString);
            }
            else if (virtualPath != null)
            {
                appPathString = configMapPath.GetAppPathForPath(appSiteID, virtualPath.VirtualPathString);
            }

            if (appPathString != null)
            {
                appPath = VirtualPath.Create(appPathString);
            }
        }
Пример #6
0
        internal static void GetConfigPaths(IConfigMapPath configMapPath, WebLevel webLevel, VirtualPath virtualPath, string site, string locationSubPath, out VirtualPath appPath, out string appSiteName, out string appSiteID, out string configPath, out string locationConfigPath)
        {
            appPath     = null;
            appSiteName = null;
            appSiteID   = null;
            if ((webLevel == WebLevel.Machine) || (virtualPath == null))
            {
                if (!string.IsNullOrEmpty(site) && string.IsNullOrEmpty(locationSubPath))
                {
                    throw System.Web.Util.ExceptionUtil.ParameterInvalid("site");
                }
                if (webLevel == WebLevel.Machine)
                {
                    configPath = "machine";
                }
                else
                {
                    configPath = "machine/webroot";
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(site))
                {
                    configMapPath.ResolveSiteArgument(site, out appSiteName, out appSiteID);
                    if (string.IsNullOrEmpty(appSiteID))
                    {
                        throw new InvalidOperationException(System.Web.SR.GetString("Config_failed_to_resolve_site_id", new object[] { site }));
                    }
                }
                else
                {
                    if (HostingEnvironment.IsHosted)
                    {
                        appSiteName = HostingEnvironment.SiteNameNoDemand;
                        appSiteID   = HostingEnvironment.SiteID;
                    }
                    if (string.IsNullOrEmpty(appSiteID))
                    {
                        configMapPath.GetDefaultSiteNameAndID(out appSiteName, out appSiteID);
                    }
                }
                configPath = GetConfigPathFromSiteIDAndVPath(appSiteID, virtualPath);
            }
            locationConfigPath = null;
            string      siteID = null;
            VirtualPath vpath  = null;

            if (locationSubPath != null)
            {
                locationConfigPath = GetConfigPathFromLocationSubPathBasic(configPath, locationSubPath);
                GetSiteIDAndVPathFromConfigPath(locationConfigPath, out siteID, out vpath);
                if (string.IsNullOrEmpty(appSiteID) && !string.IsNullOrEmpty(siteID))
                {
                    configMapPath.ResolveSiteArgument(siteID, out appSiteName, out appSiteID);
                    if (!string.IsNullOrEmpty(appSiteID))
                    {
                        locationConfigPath = GetConfigPathFromSiteIDAndVPath(appSiteID, vpath);
                    }
                    else if ((vpath == null) || (vpath.VirtualPathString == "/"))
                    {
                        appSiteName = siteID;
                        appSiteID   = siteID;
                    }
                    else
                    {
                        appSiteName = null;
                        appSiteID   = null;
                    }
                }
            }
            string appPathForPath = null;

            if (vpath != null)
            {
                appPathForPath = configMapPath.GetAppPathForPath(appSiteID, vpath.VirtualPathString);
            }
            else if (virtualPath != null)
            {
                appPathForPath = configMapPath.GetAppPathForPath(appSiteID, virtualPath.VirtualPathString);
            }
            if (appPathForPath != null)
            {
                appPath = VirtualPath.Create(appPathForPath);
            }
        }
 internal static void GetConfigPaths(IConfigMapPath configMapPath, WebLevel webLevel, VirtualPath virtualPath, string site, string locationSubPath, out VirtualPath appPath, out string appSiteName, out string appSiteID, out string configPath, out string locationConfigPath)
 {
     appPath = null;
     appSiteName = null;
     appSiteID = null;
     if ((webLevel == WebLevel.Machine) || (virtualPath == null))
     {
         if (!string.IsNullOrEmpty(site) && string.IsNullOrEmpty(locationSubPath))
         {
             throw System.Web.Util.ExceptionUtil.ParameterInvalid("site");
         }
         if (webLevel == WebLevel.Machine)
         {
             configPath = "machine";
         }
         else
         {
             configPath = "machine/webroot";
         }
     }
     else
     {
         if (!string.IsNullOrEmpty(site))
         {
             configMapPath.ResolveSiteArgument(site, out appSiteName, out appSiteID);
             if (string.IsNullOrEmpty(appSiteID))
             {
                 throw new InvalidOperationException(System.Web.SR.GetString("Config_failed_to_resolve_site_id", new object[] { site }));
             }
         }
         else
         {
             if (HostingEnvironment.IsHosted)
             {
                 appSiteName = HostingEnvironment.SiteNameNoDemand;
                 appSiteID = HostingEnvironment.SiteID;
             }
             if (string.IsNullOrEmpty(appSiteID))
             {
                 configMapPath.GetDefaultSiteNameAndID(out appSiteName, out appSiteID);
             }
         }
         configPath = GetConfigPathFromSiteIDAndVPath(appSiteID, virtualPath);
     }
     locationConfigPath = null;
     string siteID = null;
     VirtualPath vpath = null;
     if (locationSubPath != null)
     {
         locationConfigPath = GetConfigPathFromLocationSubPathBasic(configPath, locationSubPath);
         GetSiteIDAndVPathFromConfigPath(locationConfigPath, out siteID, out vpath);
         if (string.IsNullOrEmpty(appSiteID) && !string.IsNullOrEmpty(siteID))
         {
             configMapPath.ResolveSiteArgument(siteID, out appSiteName, out appSiteID);
             if (!string.IsNullOrEmpty(appSiteID))
             {
                 locationConfigPath = GetConfigPathFromSiteIDAndVPath(appSiteID, vpath);
             }
             else if ((vpath == null) || (vpath.VirtualPathString == "/"))
             {
                 appSiteName = siteID;
                 appSiteID = siteID;
             }
             else
             {
                 appSiteName = null;
                 appSiteID = null;
             }
         }
     }
     string appPathForPath = null;
     if (vpath != null)
     {
         appPathForPath = configMapPath.GetAppPathForPath(appSiteID, vpath.VirtualPathString);
     }
     else if (virtualPath != null)
     {
         appPathForPath = configMapPath.GetAppPathForPath(appSiteID, virtualPath.VirtualPathString);
     }
     if (appPathForPath != null)
     {
         appPath = VirtualPath.Create(appPathForPath);
     }
 }