static internal IConfigMapPath GetInstance()
        {
            // IIS 7 bits on <= IIS 6.x: use the metabase
            if (ServerConfig.UseMetabase)
            {
                return((IConfigMapPath)MetabaseServerConfig.GetInstance());
            }

            if (ServerConfig.IISExpressVersion != null)
            {
                return((IConfigMapPath)ServerConfig.GetInstance());
            }

            ProcessHost host = ProcessHost.DefaultHost;
            IProcessHostSupportFunctions functions = null;

            if (null != host)
            {
                functions = host.SupportFunctions;
            }

            if (functions == null)
            {
                functions = HostingEnvironment.SupportFunctions;
            }

            return(new ProcessHostMapPath(functions));
        }
        internal ProcessHostMapPath(IProcessHostSupportFunctions functions) {
            // if the functions are null and we're
            // not in a worker process, init the mgdeng config system
            if (null == functions) {
                ProcessHostConfigUtils.InitStandaloneConfig();
            }

            // we need to explicit create a COM proxy in this app domain
            // so we don't go back to the default domain or have lifetime issues
            if (null != functions) {
                _functions = Misc.CreateLocalSupportFunctions(functions);
            }

            // proactive set the config functions for
            // webengine in case this is a TCP init path
            if (null != _functions ) {
               IntPtr configSystem = _functions.GetNativeConfigurationSystem();
               Debug.Assert(IntPtr.Zero != configSystem, "null != configSystem");

               if (IntPtr.Zero != configSystem) {
                   // won't fail if valid pointer
                   // no cleanup needed, we don't own instance
                   UnsafeIISMethods.MgdSetNativeConfiguration(configSystem);
                }
            }
        }
        internal ProcessHostMapPath(IProcessHostSupportFunctions functions)
        {
            // if the functions are null and we're
            // not in a worker process, init the mgdeng config system
            if (null == functions)
            {
                ProcessHostConfigUtils.InitStandaloneConfig();
            }

            // we need to explicit create a COM proxy in this app domain
            // so we don't go back to the default domain or have lifetime issues
            if (null != functions)
            {
                _functions = Misc.CreateLocalSupportFunctions(functions);
            }

            // proactive set the config functions for
            // webengine in case this is a TCP init path
            if (null != _functions)
            {
                IntPtr configSystem = _functions.GetNativeConfigurationSystem();
                Debug.Assert(IntPtr.Zero != configSystem, "null != configSystem");

                if (IntPtr.Zero != configSystem)
                {
                    // won't fail if valid pointer
                    // no cleanup needed, we don't own instance
                    UnsafeIISMethods.MgdSetNativeConfiguration(configSystem);
                }
            }
        }
 internal static IProcessHostSupportFunctions CreateLocalSupportFunctions(IProcessHostSupportFunctions proxyFunctions)
 {
     IProcessHostSupportFunctions objectForIUnknown = null;
     IntPtr iUnknownForObject = Marshal.GetIUnknownForObject(proxyFunctions);
     if (IntPtr.Zero == iUnknownForObject)
     {
         return null;
     }
     IntPtr zero = IntPtr.Zero;
     try
     {
         Guid gUID = typeof(IProcessHostSupportFunctions).GUID;
         int errorCode = Marshal.QueryInterface(iUnknownForObject, ref gUID, out zero);
         if (errorCode < 0)
         {
             Marshal.ThrowExceptionForHR(errorCode);
         }
         objectForIUnknown = (IProcessHostSupportFunctions) Marshal.GetObjectForIUnknown(zero);
     }
     finally
     {
         if (IntPtr.Zero != zero)
         {
             Marshal.Release(zero);
         }
         if (IntPtr.Zero != iUnknownForObject)
         {
             Marshal.Release(iUnknownForObject);
         }
     }
     return objectForIUnknown;
 }
示例#5
0
        internal static IProcessHostSupportFunctions CreateLocalSupportFunctions(IProcessHostSupportFunctions proxyFunctions)
        {
            IProcessHostSupportFunctions objectForIUnknown = null;
            IntPtr iUnknownForObject = Marshal.GetIUnknownForObject(proxyFunctions);

            if (IntPtr.Zero == iUnknownForObject)
            {
                return(null);
            }
            IntPtr zero = IntPtr.Zero;

            try
            {
                Guid gUID      = typeof(IProcessHostSupportFunctions).GUID;
                int  errorCode = Marshal.QueryInterface(iUnknownForObject, ref gUID, out zero);
                if (errorCode < 0)
                {
                    Marshal.ThrowExceptionForHR(errorCode);
                }
                objectForIUnknown = (IProcessHostSupportFunctions)Marshal.GetObjectForIUnknown(zero);
            }
            finally
            {
                if (IntPtr.Zero != zero)
                {
                    Marshal.Release(zero);
                }
                if (IntPtr.Zero != iUnknownForObject)
                {
                    Marshal.Release(iUnknownForObject);
                }
            }
            return(objectForIUnknown);
        }
        ProcessHostServerConfig()
        {
            if (null == HostingEnvironment.SupportFunctions)
            {
                ProcessHostConfigUtils.InitStandaloneConfig();
            }
            else
            {
                IProcessHostSupportFunctions fns = HostingEnvironment.SupportFunctions;
                if (null != fns)
                {
                    IntPtr configSystem = fns.GetNativeConfigurationSystem();
                    Debug.Assert(IntPtr.Zero != configSystem, "null != configSystem");

                    if (IntPtr.Zero != configSystem)
                    {
                        // won't fail if valid pointer
                        // no cleanup needed, we don't own instance
                        UnsafeIISMethods.MgdSetNativeConfiguration(configSystem);
                    }
                }
            }
            _siteNameForCurrentApplication = HostingEnvironment.SiteNameNoDemand;
            if (_siteNameForCurrentApplication == null)
            {
                _siteNameForCurrentApplication = ProcessHostConfigUtils.GetSiteNameFromId(ProcessHostConfigUtils.DEFAULT_SITE_ID_UINT);
            }
        }
示例#7
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));
                }
            }
        }
 public Object GetProcessHost(IProcessHostSupportFunctions functions) {
     try {
         return ProcessHost.GetProcessHost(functions);
     }
     catch(Exception e) {
         Misc.ReportUnhandledException(e, new string[] {SR.GetString(SR.Cant_Create_Process_Host)});
         throw;
     }
 }
 public Object GetProcessHost(IProcessHostSupportFunctions functions)
 {
     try {
         return(ProcessHost.GetProcessHost(functions));
     }
     catch (Exception e) {
         Misc.ReportUnhandledException(e, new string[] { SR.GetString(SR.Cant_Create_Process_Host) });
         throw;
     }
 }
 public object GetProcessHost(IProcessHostSupportFunctions functions)
 {
     object processHost;
     try
     {
         processHost = ProcessHost.GetProcessHost(functions);
     }
     catch (Exception exception)
     {
         Misc.ReportUnhandledException(exception, new string[] { System.Web.SR.GetString("Cant_Create_Process_Host") });
         throw;
     }
     return processHost;
 }
示例#11
0
 internal static ProcessHost GetProcessHost(IProcessHostSupportFunctions functions)
 {
     if (_theProcessHost == null)
     {
         lock (_processHostStaticLock)
         {
             if (_theProcessHost == null)
             {
                 _theProcessHost = new ProcessHost(functions);
             }
         }
     }
     return(_theProcessHost);
 }
        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));
                }
            }
        }
        public object GetProcessHost(IProcessHostSupportFunctions functions)
        {
            object processHost;

            try
            {
                processHost = ProcessHost.GetProcessHost(functions);
            }
            catch (Exception exception)
            {
                Misc.ReportUnhandledException(exception, new string[] { System.Web.SR.GetString("Cant_Create_Process_Host") });
                throw;
            }
            return(processHost);
        }
示例#14
0
        internal ISAPIApplicationHost(string appIdOrVirtualPath, string physicalPath, bool validatePhysicalPath, IProcessHostSupportFunctions functions, string iisVersion = null)
        {
            this._iisVersion = iisVersion;
            this._functions  = functions;
            if (this._functions == null)
            {
                ProcessHost defaultHost = ProcessHost.DefaultHost;
                if (defaultHost != null)
                {
                    this._functions = defaultHost.SupportFunctions;
                    if (this._functions != null)
                    {
                        HostingEnvironment.SupportFunctions = this._functions;
                    }
                }
            }
            IServerConfig defaultDomainInstance = ServerConfig.GetDefaultDomainInstance(this._iisVersion);

            if (StringUtil.StringStartsWithIgnoreCase(appIdOrVirtualPath, "/LM/W3SVC/"))
            {
                this._appId       = appIdOrVirtualPath;
                this._virtualPath = VirtualPath.Create(ExtractVPathFromAppId(this._appId));
                this._siteID      = ExtractSiteIdFromAppId(this._appId);
                this._siteName    = defaultDomainInstance.GetSiteNameFromSiteID(this._siteID);
            }
            else
            {
                this._virtualPath = VirtualPath.Create(appIdOrVirtualPath);
                this._appId       = GetDefaultAppIdFromVPath(this._virtualPath.VirtualPathString);
                this._siteID      = "1";
                this._siteName    = defaultDomainInstance.GetSiteNameFromSiteID(this._siteID);
            }
            if (physicalPath == null)
            {
                this._physicalPath = defaultDomainInstance.MapPath(this, this._virtualPath);
            }
            else
            {
                this._physicalPath = physicalPath;
            }
            if (validatePhysicalPath && !Directory.Exists(this._physicalPath))
            {
                throw new HttpException(System.Web.SR.GetString("Invalid_IIS_app", new object[] { appIdOrVirtualPath }));
            }
        }
 internal ISAPIApplicationHost(string appIdOrVirtualPath, string physicalPath, bool validatePhysicalPath, IProcessHostSupportFunctions functions, string iisVersion = null)
 {
     this._iisVersion = iisVersion;
     this._functions = functions;
     if (this._functions == null)
     {
         ProcessHost defaultHost = ProcessHost.DefaultHost;
         if (defaultHost != null)
         {
             this._functions = defaultHost.SupportFunctions;
             if (this._functions != null)
             {
                 HostingEnvironment.SupportFunctions = this._functions;
             }
         }
     }
     IServerConfig defaultDomainInstance = ServerConfig.GetDefaultDomainInstance(this._iisVersion);
     if (StringUtil.StringStartsWithIgnoreCase(appIdOrVirtualPath, "/LM/W3SVC/"))
     {
         this._appId = appIdOrVirtualPath;
         this._virtualPath = VirtualPath.Create(ExtractVPathFromAppId(this._appId));
         this._siteID = ExtractSiteIdFromAppId(this._appId);
         this._siteName = defaultDomainInstance.GetSiteNameFromSiteID(this._siteID);
     }
     else
     {
         this._virtualPath = VirtualPath.Create(appIdOrVirtualPath);
         this._appId = GetDefaultAppIdFromVPath(this._virtualPath.VirtualPathString);
         this._siteID = "1";
         this._siteName = defaultDomainInstance.GetSiteNameFromSiteID(this._siteID);
     }
     if (physicalPath == null)
     {
         this._physicalPath = defaultDomainInstance.MapPath(this, this._virtualPath);
     }
     else
     {
         this._physicalPath = physicalPath;
     }
     if (validatePhysicalPath && !Directory.Exists(this._physicalPath))
     {
         throw new HttpException(System.Web.SR.GetString("Invalid_IIS_app", new object[] { appIdOrVirtualPath }));
     }
 }
示例#16
0
文件: Misc.cs 项目: dox0/DotNet471RS3
        internal static IProcessHostSupportFunctions CreateLocalSupportFunctions(IProcessHostSupportFunctions proxyFunctions)
        {
            IProcessHostSupportFunctions localFunctions = null;

            // get the underlying COM object
            IntPtr pUnk = Marshal.GetIUnknownForObject(proxyFunctions);

            // this object isn't a COM object
            if (IntPtr.Zero == pUnk)
            {
                return(null);
            }

            IntPtr ppv = IntPtr.Zero;

            try {
                // QI it for the interface
                Guid g = typeof(IProcessHostSupportFunctions).GUID;

                int hresult = Marshal.QueryInterface(pUnk, ref g, out ppv);
                if (hresult < 0)
                {
                    Marshal.ThrowExceptionForHR(hresult);
                }

                // create a RCW we can hold onto in this domain
                // this bumps the ref count so we can drop our refs on the raw interfaces
                localFunctions = (IProcessHostSupportFunctions)Marshal.GetObjectForIUnknown(ppv);
            }
            finally {
                // drop our explicit refs and keep the managed instance
                if (IntPtr.Zero != ppv)
                {
                    Marshal.Release(ppv);
                }
                if (IntPtr.Zero != pUnk)
                {
                    Marshal.Release(pUnk);
                }
            }

            return(localFunctions);
        }
 internal ProcessHostMapPath(IProcessHostSupportFunctions functions)
 {
     if (functions == null)
     {
         ProcessHostConfigUtils.InitStandaloneConfig();
     }
     if (functions != null)
     {
         this._functions = Misc.CreateLocalSupportFunctions(functions);
     }
     if (this._functions != null)
     {
         IntPtr nativeConfigurationSystem = this._functions.GetNativeConfigurationSystem();
         if (IntPtr.Zero != nativeConfigurationSystem)
         {
             UnsafeIISMethods.MgdSetNativeConfiguration(nativeConfigurationSystem);
         }
     }
     this._mapPathCacheLock = new object();
 }
 internal ProcessHostMapPath(IProcessHostSupportFunctions functions)
 {
     if (functions == null)
     {
         ProcessHostConfigUtils.InitStandaloneConfig();
     }
     if (functions != null)
     {
         this._functions = Misc.CreateLocalSupportFunctions(functions);
     }
     if (this._functions != null)
     {
         IntPtr nativeConfigurationSystem = this._functions.GetNativeConfigurationSystem();
         if (IntPtr.Zero != nativeConfigurationSystem)
         {
             UnsafeIISMethods.MgdSetNativeConfiguration(nativeConfigurationSystem);
         }
     }
     this._mapPathCacheLock = new object();
 }
示例#19
0
        // Use this instead of MapPath, as it encapsulates the correct way to invoke
        // the MapPath method. Didn't bother much with efficiency since it's called
        // so few times.
        //
        // Example inputs: MapPathInternal(appId, "/appVPath", "/bin/foo.dll");
        public static string MapPathInternal(this IProcessHostSupportFunctions supportFunctions, string appId, string appVirtualPath, string relativePath)
        {
            Debug.Assert(supportFunctions != null);
            Debug.Assert(!String.IsNullOrWhiteSpace(appId));
            Debug.Assert(!String.IsNullOrWhiteSpace(appVirtualPath) && appVirtualPath[0] == '/');
            Debug.Assert(relativePath != null);

            StringBuilder fullVirtualPath = new StringBuilder(appVirtualPath.Length + relativePath.Length + 2 /* for slashes */);

            // Ensure the app virtual path is always preceded by a slash
            if (appVirtualPath[0] != '/')
            {
                fullVirtualPath.Append('/');
            }
            fullVirtualPath.Append(appVirtualPath);

            // Ensure the app virtual path always ends with a slash
            if (fullVirtualPath[fullVirtualPath.Length - 1] != '/')
            {
                fullVirtualPath.Append('/');
            }

            // Append the relative path, removing the preceding slash if necessary
            if (relativePath.Length > 0)
            {
                if (relativePath[0] == '/')
                {
                    fullVirtualPath.Append(relativePath, 1, relativePath.Length - 1);
                }
                else
                {
                    fullVirtualPath.Append(relativePath);
                }
            }

            string physicalPath;

            supportFunctions.MapPath(appId, fullVirtualPath.ToString(), out physicalPath);
            return(physicalPath);
        }
示例#20
0
 private ProcessHost(IProcessHostSupportFunctions functions)
 {
     try
     {
         this._functions = functions;
         HostingEnvironment.SupportFunctions = functions;
         this._appManager = ApplicationManager.GetApplicationManager();
         int initialCount = (int)Misc.GetAspNetRegValue(null, "MaxPreloadConcurrency", 0);
         if (initialCount > 0)
         {
             this._preloadingThrottle = new Semaphore(initialCount, initialCount);
         }
     }
     catch (Exception exception)
     {
         using (new ProcessImpersonationContext())
         {
             Misc.ReportUnhandledException(exception, new string[] { System.Web.SR.GetString("Cant_Create_Process_Host") });
         }
         throw;
     }
 }
        internal static IConfigMapPath GetInstance()
        {
            if (ServerConfig.UseMetabase)
            {
                return((IConfigMapPath)MetabaseServerConfig.GetInstance());
            }
            if (ServerConfig.IISExpressVersion != null)
            {
                return((IConfigMapPath)ServerConfig.GetInstance());
            }
            ProcessHost defaultHost = ProcessHost.DefaultHost;
            IProcessHostSupportFunctions supportFunctions = null;

            if (defaultHost != null)
            {
                supportFunctions = defaultHost.SupportFunctions;
            }
            if (supportFunctions == null)
            {
                supportFunctions = HostingEnvironment.SupportFunctions;
            }
            return(new ProcessHostMapPath(supportFunctions));
        }
 private ProcessHostServerConfig()
 {
     if (HostingEnvironment.SupportFunctions == null)
     {
         ProcessHostConfigUtils.InitStandaloneConfig();
     }
     else
     {
         IProcessHostSupportFunctions supportFunctions = HostingEnvironment.SupportFunctions;
         if (supportFunctions != null)
         {
             IntPtr nativeConfigurationSystem = supportFunctions.GetNativeConfigurationSystem();
             if (IntPtr.Zero != nativeConfigurationSystem)
             {
                 UnsafeIISMethods.MgdSetNativeConfiguration(nativeConfigurationSystem);
             }
         }
     }
     this._siteNameForCurrentApplication = HostingEnvironment.SiteNameNoDemand;
     if (this._siteNameForCurrentApplication == null)
     {
         this._siteNameForCurrentApplication = ProcessHostConfigUtils.GetSiteNameFromId(1);
     }
 }
示例#23
0
        IObjectHandle IProcessHostLite.GetCustomLoader(string appId, string appConfigPath, out IProcessHostSupportFunctions supportFunctions, out AppDomain newlyCreatedAppDomain) {
            supportFunctions = null;
            newlyCreatedAppDomain = null;
            CustomLoaderHelperFunctions helperFunctions = new CustomLoaderHelperFunctions(_functions, appId);
            string appVirtualPath = helperFunctions.AppVirtualPath;

            try {
                string customLoaderAssemblyPhysicalPath = helperFunctions.MapPath("bin/AspNet.Loader.dll");

                if (!File.Exists(customLoaderAssemblyPhysicalPath)) {
                    return null; // no custom loader is in use; fall back to legacy hosting logic
                }

                // Technically there is a race condition between the file existence check above
                // and the assembly load that will take place shortly. We won't worry too much
                // about this since the window is very short and the application shouldn't be
                // modified during this process anyway.

                string appRootPhysicalPath = helperFunctions.AppPhysicalPath;
                string webConfigPhysicalPath = helperFunctions.MapPath("Web.config");
                bool webConfigFileExists = File.Exists(webConfigPhysicalPath);

                // The CustomLoaderHelper class is defined in System.Web.ApplicationServices.dll
                // so that OOB frameworks don't need to take a hardcoded System.Web.dll dependency.
                // There might be weird issues if we try to load a GACed System.Web.dll into the
                // same AppDomain as a bin-deployed System.Web.dll.
                supportFunctions = _functions;
                return CustomLoaderHelper.GetCustomLoader(
                    helperFunctions: helperFunctions,
                    appConfigMetabasePath: appConfigPath,
                    configFilePath: (webConfigFileExists) ? webConfigPhysicalPath : null,
                    customLoaderPhysicalPath: customLoaderAssemblyPhysicalPath,
                    newlyCreatedAppDomain: out newlyCreatedAppDomain);
            }
            catch (Exception ex) {
                SetCustomLoaderFailure(appId, ExceptionDispatchInfo.Capture(ex));
                return null;
            }
        }
示例#24
0
 // Methods
 public virtual object GetProcessHost(IProcessHostSupportFunctions functions)
 {
 }
	// Methods
	public virtual object GetProcessHost(IProcessHostSupportFunctions functions) {}
示例#26
0
        internal static IProcessHostSupportFunctions CreateLocalSupportFunctions(IProcessHostSupportFunctions proxyFunctions) {
            IProcessHostSupportFunctions localFunctions = null;

            // get the underlying COM object
            IntPtr pUnk = Marshal.GetIUnknownForObject(proxyFunctions);

            // this object isn't a COM object
            if (IntPtr.Zero == pUnk) {
                return null;
            }
            
            IntPtr ppv = IntPtr.Zero;
            try {
                // QI it for the interface
                Guid g = typeof(IProcessHostSupportFunctions).GUID;

                int hresult = Marshal.QueryInterface(pUnk, ref g, out ppv);
                if (hresult < 0)  {
                    Marshal.ThrowExceptionForHR(hresult);
                }

                // create a RCW we can hold onto in this domain
                // this bumps the ref count so we can drop our refs on the raw interfaces
                localFunctions = (IProcessHostSupportFunctions)Marshal.GetObjectForIUnknown(ppv);
            }
            finally {
                // drop our explicit refs and keep the managed instance
                if (IntPtr.Zero != ppv) {
                    Marshal.Release(ppv);
                }
                if (IntPtr.Zero != pUnk) {
                    Marshal.Release(pUnk);
                }
            }

            return localFunctions;
        }
 public Object GetProcessHost(IProcessHostSupportFunctions functions)
 {
   return default(Object);
 }
        internal void Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory,
            HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel,
            Exception appDomainCreationException) {

            _hostingParameters = hostingParameters;

            HostingEnvironmentFlags hostingFlags = HostingEnvironmentFlags.Default;
            if (_hostingParameters != null) {
                hostingFlags = _hostingParameters.HostingFlags;
                if (_hostingParameters.IISExpressVersion != null) {
                    ServerConfig.IISExpressVersion = _hostingParameters.IISExpressVersion;
                }
            }

            // Keep track of the app manager, unless HideFromAppManager flag was passed
            if ((hostingFlags & HostingEnvironmentFlags.HideFromAppManager) == 0)
                _appManager = appManager;

            if ((hostingFlags & HostingEnvironmentFlags.ClientBuildManager) != 0) {
                BuildManagerHost.InClientBuildManager = true;
            }

            if ((hostingFlags & HostingEnvironmentFlags.SupportsMultiTargeting) != 0) {
                BuildManagerHost.SupportsMultiTargeting = true;
            }


            //
            // init config system using private config if applicable
            //
            if (appHost is ISAPIApplicationHost && !ServerConfig.UseMetabase) {
                string rootWebConfigPath = ((ISAPIApplicationHost)appHost).ResolveRootWebConfigPath();
                if (!String.IsNullOrEmpty(rootWebConfigPath)) {
                    Debug.Assert(File.Exists(rootWebConfigPath), "File.Exists(rootWebConfigPath)");
                    HttpConfigurationSystem.RootWebConfigurationFilePath = rootWebConfigPath;
                }

                // we need to explicit create a COM proxy in this app domain
                // so we don't go back to the default domain or have lifetime issues
                // remember support functions
                IProcessHostSupportFunctions proxyFunctions = ((ISAPIApplicationHost)appHost).SupportFunctions;
                if (null != proxyFunctions) {
                    _functions = Misc.CreateLocalSupportFunctions(proxyFunctions);
                }
            }

            _appId = HttpRuntime.AppDomainAppId;
            _appVirtualPath = HttpRuntime.AppDomainAppVirtualPathObject;
            _appPhysicalPath = HttpRuntime.AppDomainAppPathInternal;
            _appHost = appHost;

            _configMapPath = configMapPathFactory.Create(_appVirtualPath.VirtualPathString, _appPhysicalPath);
            HttpConfigurationSystem.EnsureInit(_configMapPath, true, false);

            // attempt to cache and use IConfigMapPath2 provider
            // which supports VirtualPath's to save on conversions
            _configMapPath2 = _configMapPath as IConfigMapPath2;


            _initiateShutdownWorkItemCallback = new WaitCallback(this.InitiateShutdownWorkItemCallback);

            // notify app manager
            if (_appManager != null) {
                _appManager.HostingEnvironmentActivated(CacheMemorySizePressure.EffectiveProcessMemoryLimit);
            }

            // make sure there is always app host
            if (_appHost == null) {
                _appHost = new SimpleApplicationHost(_appVirtualPath, _appPhysicalPath);
            }
            else {
                _externalAppHost = true;
            }

            // remember the token to access config
            _configToken = _appHost.GetConfigToken();

            // Start with a MapPath based virtual path provider
            _mapPathBasedVirtualPathProvider = new MapPathBasedVirtualPathProvider();
            _virtualPathProvider = _mapPathBasedVirtualPathProvider;

            // initiaze HTTP-independent features
            HttpRuntime.InitializeHostingFeatures(hostingFlags, policyLevel, appDomainCreationException);

            // VSWhidbey 393259. Do not monitor idle timeout for CBM since Venus
            // will always restart a new appdomain if old one is shutdown.
            if (!BuildManagerHost.InClientBuildManager) {
                // start monitoring for idle inside app domain
                StartMonitoringForIdleTimeout();
            }

            // notify app manager if the app domain limit is violated
            EnforceAppDomainLimit();

            // get application identity (for explicit impersonation mode)
            GetApplicationIdentity();

            // call AppInitialize, unless the flag says not to do it (e.g. CBM scenario).
            // Also, don't call it if HostingInit failed (VSWhidbey 210495)
            if(!HttpRuntime.HostingInitFailed) {
                try {
                    BuildManager.ExecutePreAppStart();
                    if ((hostingFlags & HostingEnvironmentFlags.DontCallAppInitialize) == 0) {
                        BuildManager.CallAppInitializeMethod();
                    }
                }
                catch (Exception e) {
                    // could throw compilation errors in 'code' - report them with first http request
                    HttpRuntime.InitializationException = e;

                    if ((hostingFlags & HostingEnvironmentFlags.ThrowHostingInitErrors) != 0) {
                        throw;
                    }
                }
            }
        }
示例#29
0
        private ProcessHost(IProcessHostSupportFunctions functions) {
            try {
                // remember support functions
                _functions = functions;

                // pass them along to the HostingEnvironment in the default domain
                HostingEnvironment.SupportFunctions = functions;

                // create singleton app manager
                _appManager = ApplicationManager.GetApplicationManager();

                // For M3 we get the throttling limit from the registry.
                // Dev10\Beta1 work item 543420 is to investigate whether we need to get rid of the throttling
                int maxPreloadConcurrency = (int)Misc.GetAspNetRegValue(null, "MaxPreloadConcurrency", 0);
                if (maxPreloadConcurrency > 0) {
                    _preloadingThrottle = new System.Threading.Semaphore(maxPreloadConcurrency, maxPreloadConcurrency);
                }


            }
            catch (Exception e) {
                using (new ProcessImpersonationContext()) {
                    Misc.ReportUnhandledException(e, new string[]
                                                  { SR.GetString(SR.Cant_Create_Process_Host)});
                    Debug.Trace("internal", "ProcessHost::ctor failed with " + e.GetType().FullName + ": " + e.Message + "\r\n" + e.StackTrace);
                }
                throw;
            }
        }
示例#30
0
            internal CustomLoaderHelperFunctions(IProcessHostSupportFunctions supportFunctions, string appId) {
                _supportFunctions = supportFunctions;

                string appVirtualPath, appPhysicalPath, siteName, siteId;
                _supportFunctions.GetApplicationProperties(appId, out appVirtualPath, out appPhysicalPath, out siteName, out siteId);

                AppId = appId;
                AppVirtualPath = appVirtualPath;
                AppPhysicalPath = appPhysicalPath;
            }
 internal void Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)
 {
     this._hostingParameters = hostingParameters;
     HostingEnvironmentFlags hostingFlags = HostingEnvironmentFlags.Default;
     if (this._hostingParameters != null)
     {
         hostingFlags = this._hostingParameters.HostingFlags;
         if (this._hostingParameters.IISExpressVersion != null)
         {
             ServerConfig.IISExpressVersion = this._hostingParameters.IISExpressVersion;
         }
     }
     if ((hostingFlags & HostingEnvironmentFlags.HideFromAppManager) == HostingEnvironmentFlags.Default)
     {
         this._appManager = appManager;
     }
     if ((hostingFlags & HostingEnvironmentFlags.ClientBuildManager) != HostingEnvironmentFlags.Default)
     {
         BuildManagerHost.InClientBuildManager = true;
     }
     if ((hostingFlags & HostingEnvironmentFlags.SupportsMultiTargeting) != HostingEnvironmentFlags.Default)
     {
         BuildManagerHost.SupportsMultiTargeting = true;
     }
     if ((appHost is ISAPIApplicationHost) && !ServerConfig.UseMetabase)
     {
         string str = ((ISAPIApplicationHost) appHost).ResolveRootWebConfigPath();
         if (!string.IsNullOrEmpty(str))
         {
             HttpConfigurationSystem.RootWebConfigurationFilePath = str;
         }
         IProcessHostSupportFunctions supportFunctions = ((ISAPIApplicationHost) appHost).SupportFunctions;
         if (supportFunctions != null)
         {
             _functions = Misc.CreateLocalSupportFunctions(supportFunctions);
         }
     }
     this._appId = HttpRuntime.AppDomainAppIdInternal;
     this._appVirtualPath = HttpRuntime.AppDomainAppVirtualPathObject;
     this._appPhysicalPath = HttpRuntime.AppDomainAppPathInternal;
     this._appHost = appHost;
     this._configMapPath = configMapPathFactory.Create(this._appVirtualPath.VirtualPathString, this._appPhysicalPath);
     HttpConfigurationSystem.EnsureInit(this._configMapPath, true, false);
     this._configMapPath2 = this._configMapPath as IConfigMapPath2;
     this._initiateShutdownWorkItemCallback = new WaitCallback(this.InitiateShutdownWorkItemCallback);
     if (this._appManager != null)
     {
         this._appManager.HostingEnvironmentActivated(CacheMemorySizePressure.EffectiveProcessMemoryLimit);
     }
     if (this._appHost == null)
     {
         this._appHost = new SimpleApplicationHost(this._appVirtualPath, this._appPhysicalPath);
     }
     else
     {
         this._externalAppHost = true;
     }
     this._configToken = this._appHost.GetConfigToken();
     this._mapPathBasedVirtualPathProvider = new MapPathBasedVirtualPathProvider();
     this._virtualPathProvider = this._mapPathBasedVirtualPathProvider;
     HttpRuntime.InitializeHostingFeatures(hostingFlags, policyLevel, appDomainCreationException);
     if (!BuildManagerHost.InClientBuildManager)
     {
         this.StartMonitoringForIdleTimeout();
     }
     this.EnforceAppDomainLimit();
     this.GetApplicationIdentity();
     if (!HttpRuntime.HostingInitFailed)
     {
         try
         {
             BuildManager.CallPreStartInitMethods();
             if ((hostingFlags & HostingEnvironmentFlags.DontCallAppInitialize) == HostingEnvironmentFlags.Default)
             {
                 BuildManager.CallAppInitializeMethod();
             }
         }
         catch (Exception exception)
         {
             HttpRuntime.InitializationException = exception;
             if ((hostingFlags & HostingEnvironmentFlags.ThrowHostingInitErrors) != HostingEnvironmentFlags.Default)
             {
                 throw;
             }
         }
     }
 }
示例#32
0
        // called from ProcessHostFactoryHelper to get ProcessHost
        internal static ProcessHost GetProcessHost(IProcessHostSupportFunctions functions) {
            if (_theProcessHost == null) {
                lock (_processHostStaticLock) {
                    if (_theProcessHost == null) {
                        _theProcessHost = new ProcessHost(functions);
                    }
                }
            }

            return _theProcessHost;
        }
 public Object GetProcessHost(IProcessHostSupportFunctions functions)
 {
     return(default(Object));
 }