2 // System.Web.Hosting.HostingEnvironment.cs
5 // Chris Toshok (toshok@ximian.com)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
10 // Copyright (C) 2005,2006 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.Globalization;
36 using System.Security.Permissions;
37 using System.Threading;
38 using System.Web.Configuration;
39 using System.Web.Caching;
40 using System.Web.Util;
42 namespace System.Web.Hosting {
44 [AspNetHostingPermission (SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Medium)]
45 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.High)]
46 public sealed class HostingEnvironment : MarshalByRefObject
48 static bool is_hosted;
49 static string site_name;
50 static ApplicationShutdownReason shutdown_reason;
51 internal static BareApplicationHost Host;
52 static VirtualPathProvider vpath_provider = (HttpRuntime.AppDomainAppVirtualPath == null) ? null :
53 new DefaultVirtualPathProvider ();
54 static int busy_count;
56 public HostingEnvironment ()
58 // The documentation says that this is called once per domain by the ApplicationManager and
59 // then it throws InvalidOperationException whenever called.
60 throw new InvalidOperationException ();
63 public static string ApplicationID {
64 get { return HttpRuntime.AppDomainAppId; }
67 public static string ApplicationPhysicalPath {
68 get { return HttpRuntime.AppDomainAppPath; }
71 public static string ApplicationVirtualPath {
72 get { return HttpRuntime.AppDomainAppVirtualPath; }
75 public static Cache Cache {
76 get { return HttpRuntime.Cache; }
79 public static Exception InitializationException {
80 get { return HttpApplication.InitializationException; }
83 public static bool IsHosted {
84 get { return is_hosted; }
87 public static ApplicationShutdownReason ShutdownReason {
88 get { return shutdown_reason; }
91 public static string SiteName {
92 get { return site_name; }
95 public static VirtualPathProvider VirtualPathProvider {
96 get { return vpath_provider; }
99 public static void DecrementBusyCount ()
101 Interlocked.Decrement (ref busy_count);
104 [MonoTODO ("Not implemented")]
105 public static IDisposable Impersonate ()
107 throw new NotImplementedException ();
110 [MonoTODO ("Not implemented")]
111 public static IDisposable Impersonate (IntPtr token)
113 throw new NotImplementedException ();
116 [MonoTODO ("Not implemented")]
117 public static IDisposable Impersonate (IntPtr userToken, string virtualPath)
119 throw new NotImplementedException ();
122 public static void IncrementBusyCount ()
124 Interlocked.Increment (ref busy_count);
127 public override object InitializeLifetimeService ()
132 public static void InitiateShutdown ()
134 HttpRuntime.UnloadAppDomain ();
137 public static string MapPath (string virtualPath)
139 if (virtualPath == null || virtualPath == "")
140 throw new ArgumentNullException ("virtualPath");
142 HttpContext context = HttpContext.Current;
146 return context.Request.MapPath (virtualPath);
149 public static void RegisterObject (IRegisteredObject obj)
152 throw new ArgumentNullException ("obj");
153 Host.RegisterObject (obj, false);
156 public static void RegisterVirtualPathProvider (VirtualPathProvider virtualPathProvider)
158 if (HttpRuntime.AppDomainAppVirtualPath == null)
159 throw new InvalidOperationException ();
161 if (virtualPathProvider == null)
162 throw new ArgumentNullException ("virtualPathProvider");
164 virtualPathProvider.SetPrevious (vpath_provider);
165 vpath_provider = virtualPathProvider;
168 public static IDisposable SetCultures (string virtualPath)
170 GlobalizationSection gs = WebConfigurationManager.GetSection ("system.web/globalization", virtualPath) as GlobalizationSection;
171 IDisposable ret = Thread.CurrentThread.CurrentCulture as IDisposable;
172 string culture = gs.Culture;
173 if (String.IsNullOrEmpty (culture))
175 Thread.CurrentThread.CurrentCulture = new CultureInfo (culture);
179 public static IDisposable SetCultures ()
181 return SetCultures ("~/");
184 public static void UnregisterObject (IRegisteredObject obj)
187 throw new ArgumentNullException ("obj");
188 Host.UnregisterObject (obj);