Ejemplo n.º 1
0
        /// <summary>
        /// Uses reflection to update private members to mimic an ASP.net hosting environment
        /// to ensure that the MongoDB session state module is capable of running.
        /// </summary>
        private static void UpdateHostingEnvironment()
        {
            var virtualPathType = typeof(HttpContext).Assembly.GetType("System.Web.VirtualPath");
            var virtualPathObj  = virtualPathType.InvokeMember("Create", BindingFlags.InvokeMethod, null, null, new object[] { "/" });

            var appVirtulPath = System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath;

            System.Web.Hosting.HostingEnvironment env = new System.Web.Hosting.HostingEnvironment();
            var appVirtualPathField = env.GetType().GetField("_appVirtualPath", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            appVirtualPathField.SetValue(env, virtualPathObj);
        }
        static ConfigHelper()
        {
            string scriptRoot = ConfigurationManager.AppSettings[_scriptRootSettingKey];

            if (scriptRoot != null)
            {
                scriptRoot = scriptRoot.Trim();
            }

            if (string.IsNullOrEmpty(scriptRoot))
            {
                throw new SettingsPropertyNotFoundException(_scriptRootSettingKey);
            }

            if (scriptRoot.StartsWith("~"))
            {
                scriptRoot = WebServer.MapPath(scriptRoot);
            }

            _scriptPath = new ScriptPath(scriptRoot);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Configura o ambiente da aplicação.
        /// </summary>
        /// <param name="applicationId"></param>
        /// <param name="domainId"></param>
        /// <param name="rootPath"></param>
        public static void ConfigureEnvironment(string applicationId, string domainId, string rootPath)
        {
            AppDomain.CurrentDomain.Load(typeof(Microsoft.Owin.Host.HttpListener.OwinHttpListener).Assembly.GetName());
            if (!System.IO.Directory.Exists(rootPath))
            {
                try
                {
                    System.IO.Directory.CreateDirectory(rootPath);
                }
                catch
                {
                }
            }
            var domain = System.Threading.Thread.GetDomain();

            domain.SetData(".appPath", rootPath);
            domain.SetData(".appVPath", "/");
            domain.SetData(".appDomain", "*");
            domain.SetData(".appId", applicationId);
            domain.SetData(".domainId", domainId);
            domain.SetData(".hostingVirtualPath", "/");
            domain.SetData(".hostingInstallDir", rootPath);
            var    theRuntimeField = typeof(System.Web.HttpRuntime).GetField("_theRuntime", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
            object runtime         = null;

            if (theRuntimeField != null)
            {
                runtime = theRuntimeField.GetValue(null);
                typeof(System.Web.HttpRuntime).GetMethod("Init", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).Invoke(runtime, null);
            }
            var    path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "Temporary ASP.NET Files");
            string str  = System.IO.Path.Combine(path, applicationId);

            try
            {
                domain.SetDynamicBase(str);
            }
            catch
            {
            }
            if (theRuntimeField != null)
            {
                typeof(System.Web.HttpRuntime).GetField("_codegenDir", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(runtime, System.Threading.Thread.GetDomain().DynamicDirectory);
            }
            var appIdField = typeof(System.Web.Hosting.HostingEnvironment).GetField("_appId", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            System.Web.Hosting.HostingEnvironment hostingEnviroment = null;
            try
            {
                hostingEnviroment = new System.Web.Hosting.HostingEnvironment();
                if (appIdField != null)
                {
                    appIdField.SetValue(hostingEnviroment, System.Web.HttpRuntime.AppDomainAppId);
                }
            }
            catch
            {
            }
            var configMapPathField = typeof(System.Web.Hosting.HostingEnvironment).GetField("_configMapPath", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            if (configMapPathField != null)
            {
                var mapPath = new WebApplicationMapPath(rootPath);
                configMapPathField.SetValue(hostingEnviroment, mapPath);
            }
            var appVirtualPathField = typeof(System.Web.Hosting.HostingEnvironment).GetField("_appVirtualPath", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            if (appVirtualPathField != null)
            {
                appVirtualPathField.SetValue(hostingEnviroment, typeof(System.Web.HttpRuntime).GetProperty("AppDomainAppVirtualPathObject", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null));
            }
            var appPhysicalPathField = typeof(System.Web.Hosting.HostingEnvironment).GetField("_appPhysicalPath", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            if (appPhysicalPathField != null)
            {
                appPhysicalPathField.SetValue(hostingEnviroment, typeof(System.Web.HttpRuntime).GetProperty("AppDomainAppPathInternal", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static).GetValue(null));
            }
        }
Ejemplo n.º 4
0
		/// <summary>
		/// Uses reflection to update private members to mimic an ASP.net hosting environment
		/// to ensure that the MongoDB session state module is capable of running.
		/// </summary>
		private static void UpdateHostingEnvironment()
		{
			var virtualPathType = typeof(HttpContext).Assembly.GetType("System.Web.VirtualPath");
			var virtualPathObj = virtualPathType.InvokeMember("Create", BindingFlags.InvokeMethod, null, null, new object[] { "/" });

			var appVirtulPath = System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath;

			System.Web.Hosting.HostingEnvironment env = new System.Web.Hosting.HostingEnvironment();
			var appVirtualPathField = env.GetType().GetField("_appVirtualPath", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
			appVirtualPathField.SetValue(env, virtualPathObj);
		}