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.Security.Permissions;
36 using System.Threading;
37 using System.Web.Caching;
38 using System.Web.Util;
40 namespace System.Web.Hosting {
42 [AspNetHostingPermission (SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Medium)]
43 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.High)]
44 public sealed class HostingEnvironment : MarshalByRefObject
46 static bool is_hosted;
47 static string site_name;
48 static ApplicationShutdownReason shutdown_reason;
49 internal static BareApplicationHost Host;
50 static VirtualPathProvider vpath_provider = (HttpRuntime.AppDomainAppVirtualPath == null) ? null :
51 new DefaultVirtualPathProvider ();
52 static int busy_count;
54 public HostingEnvironment ()
56 // The documentation says that this is called once per domain by the ApplicationManager and
57 // then it throws InvalidOperationException whenever called.
58 throw new InvalidOperationException ();
61 public static string ApplicationID {
62 get { return HttpRuntime.AppDomainAppId; }
65 public static string ApplicationPhysicalPath {
66 get { return HttpRuntime.AppDomainAppPath; }
69 public static string ApplicationVirtualPath {
70 get { return HttpRuntime.AppDomainAppVirtualPath; }
73 public static Cache Cache {
74 get { return HttpRuntime.Cache; }
77 public static Exception InitializationException {
78 get { return HttpApplication.InitializationException; }
81 public static bool IsHosted {
82 get { return is_hosted; }
85 public static ApplicationShutdownReason ShutdownReason {
86 get { return shutdown_reason; }
90 public static string SiteName {
91 get { return site_name; }
94 public static VirtualPathProvider VirtualPathProvider {
95 get { return vpath_provider; }
98 public static void DecrementBusyCount ()
100 Interlocked.Decrement (ref busy_count);
104 public static IDisposable Impersonate ()
106 throw new NotImplementedException ();
110 public static IDisposable Impersonate (IntPtr token)
112 throw new NotImplementedException ();
116 public static IDisposable Impersonate (IntPtr userToken, string virtualPath)
118 throw new NotImplementedException ();
121 public static void IncrementBusyCount ()
123 Interlocked.Increment (ref busy_count);
126 public override object InitializeLifetimeService ()
131 public static void InitiateShutdown ()
133 HttpRuntime.UnloadAppDomain ();
136 public static string MapPath (string virtualPath)
138 if (virtualPath == null || virtualPath == "")
139 throw new ArgumentNullException ("virtualPath");
141 if (UrlUtils.IsRelativeUrl (virtualPath)) {
142 string msg = String.Format ("The relative virtual path '{0}', is not allowed here.", virtualPath);
143 throw new ArgumentException (msg);
146 HttpContext context = HttpContext.Current;
150 return context.Request.MapPath (virtualPath);
153 public static void RegisterObject (IRegisteredObject obj)
156 throw new ArgumentNullException ("obj");
157 Host.RegisterObject (obj, false);
160 public static void RegisterVirtualPathProvider (VirtualPathProvider virtualPathProvider)
162 if (HttpRuntime.AppDomainAppVirtualPath == null)
163 throw new InvalidOperationException ();
165 if (virtualPathProvider == null)
166 throw new ArgumentNullException ("virtualPathProvider");
168 virtualPathProvider.SetPrevious (vpath_provider);
169 vpath_provider = virtualPathProvider;
173 public static IDisposable SetCultures (string virtualPath)
175 throw new NotImplementedException ();
179 public static IDisposable SetCultures ()
181 throw new NotImplementedException ();
184 public static void UnregisterObject (IRegisteredObject obj)
187 throw new ArgumentNullException ("obj");
188 Host.UnregisterObject (obj);