run NunitWeb on GH 2.0
[mono.git] / mcs / class / System.Web / System.Web.Hosting / HostingEnvironment.cs
1 //
2 // System.Web.Hosting.HostingEnvironment.cs
3 //
4 // Author:
5 //      Chris Toshok (toshok@ximian.com)
6 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 //
8
9 //
10 // Copyright (C) 2005,2006 Novell, Inc (http://www.novell.com)
11 //
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:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
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.
30 //
31
32 #if NET_2_0
33
34 using System;
35 using System.Security.Permissions;
36 using System.Threading;
37 using System.Web.Caching;
38 using System.Web.Util;
39
40 namespace System.Web.Hosting {
41
42         [AspNetHostingPermission (SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Medium)]
43         [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.High)]
44         public sealed class HostingEnvironment : MarshalByRefObject
45         {
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;
53
54                 public HostingEnvironment ()
55                 {
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 ();
59                 }
60
61                 public static string ApplicationID {
62                         get { return HttpRuntime.AppDomainAppId; }
63                 }
64
65                 public static string ApplicationPhysicalPath {
66                         get { return HttpRuntime.AppDomainAppPath; }
67                 }
68
69                 public static string ApplicationVirtualPath {
70                         get { return HttpRuntime.AppDomainAppVirtualPath; }
71                 }
72
73                 public static Cache Cache {
74                         get { return HttpRuntime.Cache; }
75                 }
76
77                 public static Exception InitializationException {
78                         get { return HttpApplication.InitializationException; }
79                 }
80
81                 public static bool IsHosted {
82                         get { return is_hosted; }
83                 }
84
85                 public static ApplicationShutdownReason ShutdownReason {
86                         get { return shutdown_reason; }
87                 }
88
89                 [MonoTODO]
90                 public static string SiteName {
91                         get { return site_name; }
92                 }
93
94                 public static VirtualPathProvider VirtualPathProvider {
95                         get { return vpath_provider; }
96                 }
97
98                 public static void DecrementBusyCount ()
99                 {
100                         Interlocked.Decrement (ref busy_count);
101                 }
102
103                 [MonoTODO]
104                 public static IDisposable Impersonate ()
105                 {
106                         throw new NotImplementedException ();
107                 }
108
109                 [MonoTODO]
110                 public static IDisposable Impersonate (IntPtr token)
111                 {
112                         throw new NotImplementedException ();
113                 }
114
115                 [MonoTODO]
116                 public static IDisposable Impersonate (IntPtr userToken, string virtualPath)
117                 {
118                         throw new NotImplementedException ();
119                 }
120
121                 public static void IncrementBusyCount ()
122                 {
123                         Interlocked.Increment (ref busy_count);
124                 }
125
126                 public override object InitializeLifetimeService ()
127                 {
128                         return null;
129                 }
130
131                 public static void InitiateShutdown ()
132                 {
133                         HttpRuntime.UnloadAppDomain ();
134                 }
135
136                 public static string MapPath (string virtualPath)
137                 {
138                         if (virtualPath == null || virtualPath == "")
139                                 throw new ArgumentNullException ("virtualPath");
140
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);
144                         }
145
146                         HttpContext context = HttpContext.Current;
147                         if (context == null)
148                                 return null;
149
150                         return context.Request.MapPath (virtualPath);
151                 }
152
153                 public static void RegisterObject (IRegisteredObject obj)
154                 {
155                         if (obj == null)
156                                 throw new ArgumentNullException ("obj");
157                         Host.RegisterObject (obj, false);
158                 }
159
160                 public static void RegisterVirtualPathProvider (VirtualPathProvider virtualPathProvider)
161                 {
162                         if (HttpRuntime.AppDomainAppVirtualPath == null)
163                                 throw new InvalidOperationException ();
164
165                         if (virtualPathProvider == null)
166                                 throw new ArgumentNullException ("virtualPathProvider");
167
168                         virtualPathProvider.SetPrevious (vpath_provider);
169                         vpath_provider = virtualPathProvider;
170                 }
171                 
172                 [MonoTODO]
173                 public static IDisposable SetCultures (string virtualPath)
174                 {
175                         throw new NotImplementedException ();
176                 }
177
178                 [MonoTODO]
179                 public static IDisposable SetCultures ()
180                 {
181                         throw new NotImplementedException ();
182                 }
183
184                 public static void UnregisterObject (IRegisteredObject obj)
185                 {
186                         if (obj == null)
187                                 throw new ArgumentNullException ("obj");
188                         Host.UnregisterObject (obj);
189                 }
190         }
191 }
192
193 #endif