VirtualPath GetAppPathForPathWorker(string siteID, VirtualPath path)
        {
            uint siteValue = 0;

            if (!UInt32.TryParse(siteID, out siteValue))
            {
                return(VirtualPath.RootVirtualPath);
            }

            IntPtr pBstr = IntPtr.Zero;
            int    cBstr = 0;
            string appPath;

            try {
                int result = _nativeConfig.MgdGetAppPathForPath(siteValue, path.VirtualPathString, out pBstr, out cBstr);
                appPath = (result == 0 && cBstr > 0) ? StringUtil.StringFromWCharPtr(pBstr, cBstr) : null;
            }
            finally {
                if (pBstr != IntPtr.Zero)
                {
                    Marshal.FreeBSTR(pBstr);
                }
            }

            return((appPath != null) ? VirtualPath.Create(appPath) : VirtualPath.RootVirtualPath);
        }
 protected override void PrepareParse()
 {
     if (((base.PagesConfig != null) && (base.PagesConfig.MasterPageFileInternal != null)) && (base.PagesConfig.MasterPageFileInternal.Length != 0))
     {
         base.AddDependency(VirtualPath.Create(base.PagesConfig.MasterPageFileInternal));
     }
 }
        VirtualPath GetAppPathForPathWorker(string siteID, VirtualPath path)
        {
            Debug.Trace("MapPath", "ProcHostMP.GetAppPathForPath(" + siteID + ", " + path.VirtualPathString + ")\n");

            uint siteValue = 0;

            if (!UInt32.TryParse(siteID, out siteValue))
            {
                return(VirtualPath.RootVirtualPath);
            }

            IntPtr pBstr = IntPtr.Zero;
            int    cBstr = 0;
            string appPath;

            try {
                int result = UnsafeIISMethods.MgdGetAppPathForPath(IntPtr.Zero, siteValue, path.VirtualPathString, out pBstr, out cBstr);
                appPath = (result == 0 && cBstr > 0) ? StringUtil.StringFromWCharPtr(pBstr, cBstr) : null;
            }
            finally {
                if (pBstr != IntPtr.Zero)
                {
                    Marshal.FreeBSTR(pBstr);
                }
            }

            return((appPath != null) ? VirtualPath.Create(appPath) : VirtualPath.RootVirtualPath);
        }
        internal VirtualPath CombineVirtualPaths(VirtualPath basePath, VirtualPath relativePath)
        {
            string virtualPath = CombineVirtualPaths(basePath.VirtualPathString,
                                                     relativePath.VirtualPathString);

            return(VirtualPath.Create(virtualPath));
        }
        public static bool CheckUrlAccessForPrincipal(string virtualPath, IPrincipal user, string verb)
        {
            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (verb == null)
            {
                throw new ArgumentNullException("verb");
            }
            verb = verb.Trim();
            VirtualPath path = VirtualPath.Create(virtualPath);

            if (!path.IsWithinAppRoot)
            {
                throw new ArgumentException(System.Web.SR.GetString("Virtual_path_outside_application_not_supported"), "virtualPath");
            }
            if (!s_EnabledDetermined)
            {
                if (!HttpRuntime.UseIntegratedPipeline)
                {
                    HttpModulesSection httpModules = RuntimeConfig.GetConfig().HttpModules;
                    int count = httpModules.Modules.Count;
                    for (int i = 0; i < count; i++)
                    {
                        HttpModuleAction action = httpModules.Modules[i];
                        if (Type.GetType(action.Type, false) == typeof(UrlAuthorizationModule))
                        {
                            s_Enabled = true;
                            break;
                        }
                    }
                }
                else
                {
                    foreach (ModuleConfigurationInfo info in HttpApplication.IntegratedModuleList)
                    {
                        if (Type.GetType(info.Type, false) == typeof(UrlAuthorizationModule))
                        {
                            s_Enabled = true;
                            break;
                        }
                    }
                }
                s_EnabledDetermined = true;
            }
            if (s_Enabled)
            {
                AuthorizationSection authorization = RuntimeConfig.GetConfig(path).Authorization;
                if (!authorization.EveryoneAllowed)
                {
                    return(authorization.IsUserAllowed(user, verb));
                }
            }
            return(true);
        }
 /// <devdoc>
 /// Validates that the WebResource.axd handler is registered in config and actually
 /// points to the correct handler type.
 /// </devdoc>
 private static void EnsureHandlerExistenceChecked()
 {
     // First we have to check that the handler is registered:
     // <add path="WebResource.axd" verb="GET" type="System.Web.Handlers.AssemblyResourceLoader" validate="True" />
     if (!_handlerExistenceChecked)
     {
         HttpContext       context           = HttpContext.Current;
         IIS7WorkerRequest iis7WorkerRequest = (context != null) ? context.WorkerRequest as IIS7WorkerRequest : null;
         string            webResourcePath   = UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, _webResourceUrl);
         if (iis7WorkerRequest != null)
         {
             // check the IIS <handlers> section by mapping the handler
             string handlerTypeString = iis7WorkerRequest.MapHandlerAndGetHandlerTypeString(method: "GET",
                                                                                            path: UrlPath.Combine(HttpRuntime.AppDomainAppVirtualPathString, _webResourceUrl),
                                                                                            convertNativeStaticFileModule: false, ignoreWildcardMappings: true);
             if (!String.IsNullOrEmpty(handlerTypeString))
             {
                 _handlerExists = (typeof(AssemblyResourceLoader) == BuildManager.GetType(handlerTypeString, true /*throwOnFail*/, false /*ignoreCase*/));
             }
         }
         else
         {
             // check the <httpHandlers> section
             HttpHandlerAction httpHandler = RuntimeConfig.GetConfig(VirtualPath.Create(webResourcePath)).HttpHandlers.FindMapping("GET", VirtualPath.Create(_webResourceUrl));
             _handlerExists = (httpHandler != null) && (httpHandler.TypeInternal == typeof(AssemblyResourceLoader));
         }
         _handlerExistenceChecked = true;
     }
 }
        private VirtualPath GetAppPathForPathWorker(string siteID, VirtualPath path)
        {
            string str;
            uint   result = 0;

            if (!uint.TryParse(siteID, out result))
            {
                return(VirtualPath.RootVirtualPath);
            }
            IntPtr zero    = IntPtr.Zero;
            int    cchPath = 0;

            try
            {
                str = ((this._nativeConfig.MgdGetAppPathForPath(result, path.VirtualPathString, out zero, out cchPath) == 0) && (cchPath > 0)) ? StringUtil.StringFromWCharPtr(zero, cchPath) : null;
            }
            finally
            {
                if (zero != IntPtr.Zero)
                {
                    Marshal.FreeBSTR(zero);
                }
            }
            if (str == null)
            {
                return(VirtualPath.RootVirtualPath);
            }
            return(VirtualPath.Create(str));
        }
Beispiel #8
0
        internal ISAPIApplicationHost(string appIdOrVirtualPath, string physicalPath, bool validatePhysicalPath, IProcessHostSupportFunctions functions, string iisVersion = null)
        {
            _iisVersion = iisVersion;
            // appIdOrVirtualPath is either a full metabase path, or just a virtual path
            // e.g. /LM/W3SVC/1/Root/MyApp ot /MyApp
            // Figure out which one we have, and get the other one from it
            _functions = functions;

            // make sure the functions are set in the default domain
            if (null == _functions)
            {
                ProcessHost h = ProcessHost.DefaultHost;

                if (null != h)
                {
                    _functions = h.SupportFunctions;

                    if (null != _functions)
                    {
                        HostingEnvironment.SupportFunctions = _functions;
                    }
                }
            }

            IServerConfig serverConfig = ServerConfig.GetDefaultDomainInstance(_iisVersion);

            if (StringUtil.StringStartsWithIgnoreCase(appIdOrVirtualPath, LMW3SVC_PREFIX))
            {
                _appId       = appIdOrVirtualPath;
                _virtualPath = VirtualPath.Create(ExtractVPathFromAppId(_appId));
                _siteID      = ExtractSiteIdFromAppId(_appId);
                _siteName    = serverConfig.GetSiteNameFromSiteID(_siteID);
            }
            else
            {
                _virtualPath = VirtualPath.Create(appIdOrVirtualPath);
                _appId       = GetDefaultAppIdFromVPath(_virtualPath.VirtualPathString);
                _siteID      = DEFAULT_SITEID;
                _siteName    = serverConfig.GetSiteNameFromSiteID(_siteID);
            }

            // Get the physical path from the virtual path if it wasn't passed in
            if (physicalPath == null)
            {
                _physicalPath = serverConfig.MapPath(this, _virtualPath);
            }
            else
            {
                _physicalPath = physicalPath;
            }

            if (validatePhysicalPath)
            {
                if (!Directory.Exists(_physicalPath))
                {
                    throw new HttpException(SR.GetString(SR.Invalid_IIS_app, appIdOrVirtualPath));
                }
            }
        }
Beispiel #9
0
 internal virtual void ProcessMainDirectiveAttribute(string deviceName, string name, string value)
 {
     if (name == "src")
     {
         string nonEmptyAttribute = Util.GetNonEmptyAttribute(name, value);
         this.AddDependency(VirtualPath.Create(nonEmptyAttribute));
     }
 }
Beispiel #10
0
        System.Web.Configuration.IConfigMapPath System.Web.Configuration.IConfigMapPathFactory.Create(string virtualPath, string physicalPath)
        {
            var fileMap = new System.Web.Configuration.WebConfigurationFileMap();
            var path    = VirtualPath.Create(virtualPath);

            fileMap.VirtualDirectories.Add(path.VirtualPathStringNoTrailingSlash, new System.Web.Configuration.VirtualDirectoryMapping(physicalPath, true));
            return(new System.Web.Configuration.UserMapPath(fileMap));
        }
 public string GenerateCode(string virtualPath, string virtualFileString, out IDictionary linePragmasTable)
 {
     if (virtualPath == null)
     {
         throw new ArgumentNullException("virtualPath");
     }
     this.EnsureHostCreated();
     return(this._host.GenerateCode(VirtualPath.Create(virtualPath), virtualFileString, out linePragmasTable));
 }
 public string[] GetTopLevelAssemblyReferences(string virtualPath)
 {
     if (virtualPath == null)
     {
         throw new ArgumentNullException("virtualPath");
     }
     this.EnsureHostCreated();
     return(this._host.GetTopLevelAssemblyReferences(VirtualPath.Create(virtualPath)));
 }
Beispiel #13
0
        public static Type GetCompiledType(string inputFile, HttpContext context)
        {
            // NOTE: the inputFile parameter should be named virtualPath, but cannot be changed
            // as it would be a minor breaking change! (VSWhidbey 80997).
            BuildResultCompiledType result = (BuildResultCompiledType)BuildManager.GetVPathBuildResult(
                context, VirtualPath.Create(inputFile));

            return(result.ResultType);
        }
 public void GetCompilerParameters(string virtualPath, out Type codeDomProviderType, out CompilerParameters compilerParameters)
 {
     if (virtualPath == null)
     {
         throw new ArgumentNullException("virtualPath");
     }
     this.EnsureHostCreated();
     this._host.GetCompilerParams(VirtualPath.Create(virtualPath), out codeDomProviderType, out compilerParameters);
 }
 public CodeCompileUnit GenerateCodeCompileUnit(string virtualPath, string virtualFileString, out Type codeDomProviderType, out CompilerParameters compilerParameters, out IDictionary linePragmasTable)
 {
     if (virtualPath == null)
     {
         throw new ArgumentNullException("virtualPath");
     }
     this.EnsureHostCreated();
     return(this._host.GenerateCodeCompileUnit(VirtualPath.Create(virtualPath), virtualFileString, out codeDomProviderType, out compilerParameters, out linePragmasTable));
 }
        IConfigMapPath IConfigMapPathFactory.Create(string virtualPath, string physicalPath)
        {
            WebConfigurationFileMap fileMap = new WebConfigurationFileMap();
            VirtualPath             path    = VirtualPath.Create(virtualPath);

            fileMap.VirtualDirectories.Add(path.VirtualPathStringNoTrailingSlash, new VirtualDirectoryMapping(physicalPath, true));
            fileMap.VirtualDirectories.Add(HttpRuntime.AspClientScriptVirtualPath, new VirtualDirectoryMapping(HttpRuntime.AspClientScriptPhysicalPathInternal, false));
            return(new UserMapPath(fileMap));
        }
        internal Type GetReferencedType(VirtualPath virtualPath, bool allowNoCompile)
        {
            virtualPath = base.ResolveVirtualPath(virtualPath);
            if ((base._pageParserFilter != null) && !base._pageParserFilter.AllowVirtualReference(base.CompConfig, virtualPath))
            {
                base.ProcessError(System.Web.SR.GetString("Reference_not_allowed", new object[] { virtualPath }));
            }
            BuildResult vPathBuildResult = null;
            Type        baseType         = null;

            try
            {
                vPathBuildResult = BuildManager.GetVPathBuildResult(virtualPath);
            }
            catch (HttpCompileException exception)
            {
                if (exception.VirtualPathDependencies != null)
                {
                    foreach (string str in exception.VirtualPathDependencies)
                    {
                        base.AddSourceDependency(VirtualPath.Create(str));
                    }
                }
                throw;
            }
            catch
            {
                if (this.IgnoreParseErrors)
                {
                    base.AddSourceDependency(virtualPath);
                }
                throw;
            }
            BuildResultNoCompileTemplateControl control = vPathBuildResult as BuildResultNoCompileTemplateControl;

            if (control != null)
            {
                if (!allowNoCompile)
                {
                    return(null);
                }
                baseType = control.BaseType;
            }
            else
            {
                if (!(vPathBuildResult is BuildResultCompiledType))
                {
                    throw new HttpException(System.Web.SR.GetString("Invalid_typeless_reference", new object[] { "src" }));
                }
                BuildResultCompiledType type2 = (BuildResultCompiledType)vPathBuildResult;
                baseType = type2.ResultType;
            }
            base.AddTypeDependency(baseType);
            base.AddBuildResultDependency(vPathBuildResult);
            return(baseType);
        }
    private static bool IsAppRoot(VirtualPath path)
    {
        if (s_appVirtualPath == null)
        {
            s_appVirtualPath = VirtualPath.Create(HttpRuntime.AppDomainAppVirtualPathObject.VirtualPathStringNoTrailingSlash);
        }
        VirtualPath path2 = VirtualPath.Create(path.VirtualPathStringNoTrailingSlash);

        return(s_appVirtualPath.Equals(path2));
    }
Beispiel #19
0
        protected SimpleWebHandlerParser(HttpContext context, string virtualPath, string physicalPath)
        {
            // These obsolete parameters should never be set
            Debug.Assert(context == null);
            Debug.Assert(physicalPath == null);

            Debug.Assert(virtualPath != null);

            _virtualPath = VirtualPath.Create(virtualPath);
        }
Beispiel #20
0
        internal static VirtualPath GetAndRemoveVirtualPathAttribute(IDictionary directives, string key, bool required)
        {
            string virtualPath = GetAndRemoveNonEmptyAttribute(directives, key, required);

            if (virtualPath == null)
            {
                return(null);
            }
            return(VirtualPath.Create(virtualPath));
        }
Beispiel #21
0
        public string GetAppPathForPath(string siteID, string path)
        {
            VirtualPath appPathForPath = this.GetAppPathForPath(siteID, VirtualPath.Create(path));

            if (appPathForPath == null)
            {
                return(null);
            }
            return(appPathForPath.VirtualPathString);
        }
Beispiel #22
0
 protected override void PrepareParse()
 {
     if (PagesConfig != null)
     {
         if (PagesConfig.MasterPageFileInternal != null && PagesConfig.MasterPageFileInternal.Length != 0)
         {
             AddDependency(VirtualPath.Create(PagesConfig.MasterPageFileInternal));
         }
     }
 }
Beispiel #23
0
 internal virtual void ProcessMainDirectiveAttribute(string deviceName, string name,
                                                     string value)
 {
     // A "src" attribute is equivalent to an imported source file
     if (name == "src")
     {
         string src = Util.GetNonEmptyAttribute(name, value);
         AddDependency(VirtualPath.Create(src));
     }
 }
Beispiel #24
0
        public string GetAppPathForPath(string siteID, string path)
        {
            VirtualPath resolved = GetAppPathForPath(siteID, VirtualPath.Create(path));

            if (resolved == null)
            {
                return(null);
            }

            return(resolved.VirtualPathString);
        }
Beispiel #25
0
        internal static VirtualPath GetScriptLocation()
        {
            string format = (string)RuntimeConfig.GetAppConfig().WebControls["clientScriptsLocation"];

            if (format.IndexOf("{0}", StringComparison.Ordinal) >= 0)
            {
                string str2 = "system_web";
                string str3 = VersionInfo.EngineVersion.Substring(0, VersionInfo.EngineVersion.LastIndexOf('.')).Replace('.', '_');
                format = string.Format(CultureInfo.InvariantCulture, format, new object[] { str2, str3 });
            }
            return(VirtualPath.Create(format));
        }
Beispiel #26
0
        /*
         * Process a server side include.  e.g. <!-- #include file="foo.inc" -->
         */
        private void ProcessServerInclude(Match match)
        {
            string pathType = match.Groups["pathtype"].Value;
            string filename = match.Groups["filename"].Value;

            if (filename.Length == 0)
            {
                return;
            }

            VirtualPath newVirtualPath;
            string      newPhysicalPath = null;

            if (StringUtil.EqualsIgnoreCase(pathType, "file"))
            {
                if (UrlPath.IsAbsolutePhysicalPath(filename))
                {
                    // If it's an absolute physical path, use it as is
                    newPhysicalPath = filename;

                    // Reuse the current virtual path
                    newVirtualPath = CurrentVirtualPath;
                }
                else
                {
                    // If it's relative, just treat it as virtual
                    newVirtualPath = ResolveVirtualPath(VirtualPath.Create(filename));
                }
            }
            else if (StringUtil.EqualsIgnoreCase(pathType, "virtual"))
            {
                newVirtualPath = ResolveVirtualPath(VirtualPath.Create(filename));
            }
            else
            {
                // Unknown #include type: ignore it
                return;
            }

            VirtualPath prevVirtualPath = _virtualPath;

            try {
                _virtualPath = newVirtualPath;

                // Parse the included file recursively
                ParseFile(newPhysicalPath, newVirtualPath);
            }
            finally {
                // Restore the paths
                _virtualPath = prevVirtualPath;
            }
        }
Beispiel #27
0
        public static IHttpHandler GetCompiledPageInstance(string virtualPath,
                                                           string inputFile, HttpContext context)
        {
            // Canonicalize the path to avoid failure caused by the CheckSuspiciousPhysicalPath
            // security check, which was not meant to apply to this scenario (plus this API requires
            // full trust).  VSWhidbey 541640.
            if (!String.IsNullOrEmpty(inputFile))
            {
                inputFile = Path.GetFullPath(inputFile);
            }

            return(GetCompiledPageInstance(VirtualPath.Create(virtualPath), inputFile, context));
        }
        /*
         * Returns an array of the assemblies defined in the bin and assembly reference config section
         */

        public String[] GetTopLevelAssemblyReferences(string virtualPath)
        {
            Debug.Trace("CBM", "GetHostedVirtualCodeDirectories");

            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }

            EnsureHostCreated();

            return(_host.GetTopLevelAssemblyReferences(VirtualPath.Create(virtualPath)));
        }
        /*
         * Returns the compiler type and parameters that need to be used to build
         * a given file.
         */

        public void GetCompilerParameters(string virtualPath,
                                          out Type codeDomProviderType, out CompilerParameters compilerParameters)
        {
            Debug.Trace("CBM", "GetCompilerParameters " + virtualPath);

            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }

            EnsureHostCreated();

            _host.GetCompilerParams(VirtualPath.Create(virtualPath), out codeDomProviderType, out compilerParameters);
        }
        public string GenerateCode(
            string virtualPath, String virtualFileString, out IDictionary linePragmasTable)
        {
            Debug.Trace("CBM", "GenerateCode " + virtualPath);

            if (virtualPath == null)
            {
                throw new ArgumentNullException("virtualPath");
            }

            EnsureHostCreated();

            return(_host.GenerateCode(VirtualPath.Create(virtualPath), virtualFileString, out linePragmasTable));
        }