#endif
namespace System.Web {
-
// CAS - no InheritanceDemand here as the class is sealed
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed partial class HttpContext : IServiceProvider {
object config_timeout;
int timeout_possible;
DateTime time_stamp = DateTime.UtcNow;
+ Timer timer;
+ Thread thread;
+ bool _isProcessingInclude;
+
#if NET_2_0
+ [ThreadStatic]
+ static ResourceProviderFactory provider_factory;
+ [ThreadStatic]
+ static Dictionary <string, IResourceProvider> resource_providers;
+
#if TARGET_JVM
const string app_global_res_key = "HttpContext.app_global_res_key";
internal static Assembly AppGlobalResourcesAssembly {
set { AppDomain.CurrentDomain.SetData (app_global_res_key, value); }
}
#else
+ [ThreadStatic]
+ static Dictionary <ResourceManagerCacheKey, ResourceManager> resourceManagerCache;
internal static Assembly AppGlobalResourcesAssembly;
#endif
ProfileBase profile = null;
LinkedList<IHttpHandler> handlers;
#endif
-
+
public HttpContext (HttpWorkerRequest wr)
{
WorkerRequest = wr;
}
+ internal bool IsProcessingInclude {
+ get { return _isProcessingInclude; }
+ set { _isProcessingInclude = value; }
+ }
+
public Exception [] AllErrors {
get {
if (errors == null)
}
}
+ internal Cache InternalCache {
+ get {
+ return HttpRuntime.InternalCache;
+ }
+ }
+
//
// The "Current" property is set just after we have constructed it with
// the 'HttpContext (HttpWorkerRequest)' constructor.
public bool IsCustomErrorEnabled {
get {
+ try {
+ return IsCustomErrorEnabledUnsafe;
+ }
+ catch {
+ return false;
+ }
+ }
+ }
+
+ internal bool IsCustomErrorEnabledUnsafe {
+ get {
#if NET_2_0
CustomErrorsSection cfg = (CustomErrorsSection) WebConfigurationManager.GetSection ("system.web/customErrors");
#else
if (cfg.Mode == CustomErrorMode.On)
return true;
- return (cfg.Mode == CustomErrorMode.RemoteOnly) &&
- (Request.WorkerRequest.GetLocalAddress () != Request.UserHostAddress);
+ return (cfg.Mode == CustomErrorMode.RemoteOnly) && !Request.IsLocal;
}
}
#if !TARGET_JVM
public bool IsDebuggingEnabled {
- get {
-#if NET_2_0
- CompilationSection section = (CompilationSection) WebConfigurationManager.GetSection ("system.web/compilation");
- return section.Debug;
-#else
- try {
- return CompilationConfiguration.GetInstance (this).Debug;
- } catch {
- return false;
- }
-#endif
- }
+ get { return HttpRuntime.IsDebuggingEnabled; }
}
#endif
public IDictionary Items {
}
}
-#if NET_2_0
+#if NET_2_0
+ internal bool MapRequestHandlerDone {
+ get;
+ set;
+ }
+
+ // The two properties below are defined only when the IIS7 integrated mode is used.
+ // They are useless under Mono
+ public RequestNotification CurrentNotification {
+ get { throw new PlatformNotSupportedException ("This property is not supported on Mono."); }
+ }
+
+ public bool IsPostNotification {
+ get { throw new PlatformNotSupportedException ("This property is not supported on Mono."); }
+ }
+
internal void PushHandler (IHttpHandler handler)
{
if (handler == null)
get { return GetPreviousHandler (); }
}
+ internal bool ProfileInitialized {
+ get { return profile != null; }
+ }
+
public ProfileBase Profile {
get {
if (profile == null) {
errors = null;
}
+ internal bool HasError (Exception e)
+ {
+ if (errors == e)
+ return true;
+
+ return (errors is ArrayList) ?
+ ((ArrayList) errors).Contains (e) : false;
+ }
+
public void ClearError ()
{
errors = null;
{
ResourceManager rm;
try {
- rm = new ResourceManager (classKey, assembly);
+ if (resourceManagerCache == null)
+ resourceManagerCache = new Dictionary <ResourceManagerCacheKey, ResourceManager> ();
+
+ ResourceManagerCacheKey key = new ResourceManagerCacheKey (classKey, assembly);
+ if (!resourceManagerCache.TryGetValue (key, out rm)) {
+ rm = new ResourceManager (classKey, assembly);
+ rm.IgnoreCase = true;
+ resourceManagerCache.Add (key, rm);
+ }
+
return rm.GetObject (resourceKey, culture);
} catch (MissingManifestResourceException) {
throw;
return GetGlobalResourceObject (classKey, resourceKey, Thread.CurrentThread.CurrentUICulture);
}
+ static bool EnsureProviderFactory ()
+ {
+ if (resource_providers == null)
+ resource_providers = new Dictionary <string, IResourceProvider> ();
+
+ if (provider_factory != null)
+ return true;
+
+ GlobalizationSection gs = WebConfigurationManager.GetSection ("system.web/globalization") as GlobalizationSection;
+
+ if (gs == null)
+ return false;
+
+ String rsfTypeName = gs.ResourceProviderFactoryType;
+ if (String.IsNullOrEmpty (rsfTypeName))
+ return false;
+
+ Type rsfType = HttpApplication.LoadType (rsfTypeName, true);
+ ResourceProviderFactory rpf = Activator.CreateInstance (rsfType) as ResourceProviderFactory;
+
+ if (rpf == null)
+ return false;
+
+ provider_factory = rpf;
+ return true;
+ }
+
+ internal static IResourceProvider GetResourceProvider (string key, bool isLocal)
+ {
+ if (!EnsureProviderFactory ())
+ return null;
+
+ IResourceProvider rp = null;
+ if (!resource_providers.TryGetValue (key, out rp)) {
+ if (isLocal)
+ rp = provider_factory.CreateLocalResourceProvider (key);
+ else
+ rp = provider_factory.CreateGlobalResourceProvider (key);
+ if (rp == null)
+ return null;
+ resource_providers.Add (key, rp);
+ }
+
+ return rp;
+ }
+
+ static object GetGlobalObjectFromFactory (string classKey, string resourceKey, CultureInfo culture)
+ {
+ // FIXME: Retention of data
+ IResourceProvider rp = GetResourceProvider (classKey, false);
+ if (rp == null)
+ return null;
+
+ return rp.GetObject (resourceKey, culture);
+ }
+
public static object GetGlobalResourceObject (string classKey, string resourceKey, CultureInfo culture)
{
+ object ret = GetGlobalObjectFromFactory (classKey, resourceKey, culture);
+ if (ret != null)
+ return ret;
+
if (AppGlobalResourcesAssembly == null)
- throw new MissingManifestResourceException ();
+ return null;
+
return GetResourceObject ("Resources." + classKey, resourceKey, culture, AppGlobalResourcesAssembly);
}
return GetLocalResourceObject (virtualPath, resourceKey, Thread.CurrentThread.CurrentUICulture);
}
+ static object GetLocalObjectFromFactory (string virtualPath, string resourceKey, CultureInfo culture)
+ {
+ IResourceProvider rp = GetResourceProvider (virtualPath, true);
+ if (rp == null)
+ return null;
+
+ return rp.GetObject (resourceKey, culture);
+ }
+
public static object GetLocalResourceObject (string virtualPath, string resourceKey, CultureInfo culture)
{
if (!VirtualPathUtility.IsAbsolute (virtualPath))
throw new ArgumentException ("The specified virtualPath was not rooted.");
+
+ object ret = GetLocalObjectFromFactory (virtualPath, resourceKey, culture);
+ if (ret != null)
+ return ret;
- string path = Path.GetDirectoryName (virtualPath);
+ string path = VirtualPathUtility.GetDirectory (virtualPath);
Assembly asm = AppResourcesCompiler.GetCachedLocalResourcesAssembly (path);
if (asm == null) {
AppResourcesCompiler ac = new AppResourcesCompiler (path);
}
path = Path.GetFileName (virtualPath);
- return GetResourceObject ("Resources." + path, resourceKey, culture, asm);
+ return GetResourceObject (path, resourceKey, culture, asm);
}
public object GetSection (string name)
{
return WebConfigurationManager.GetSection (name);
}
+
+ sealed class ResourceManagerCacheKey
+ {
+ readonly string _name;
+ readonly Assembly _asm;
+
+ public ResourceManagerCacheKey (string name, Assembly asm)
+ {
+ _name = name;
+ _asm = asm;
+ }
+
+ public override bool Equals (object obj)
+ {
+ if (!(obj is ResourceManagerCacheKey))
+ return false;
+ ResourceManagerCacheKey key = (ResourceManagerCacheKey) obj;
+ return key._asm == _asm && _name.Equals (key._name, StringComparison.Ordinal);
+ }
+
+ public override int GetHashCode ()
+ {
+ return _name.GetHashCode () + _asm.GetHashCode ();
+ }
+ }
#endif
object IServiceProvider.GetService (Type service)
{
return null;
}
+#if NET_2_0
+ public void RemapHandler (IHttpHandler handler)
+ {
+ if (MapRequestHandlerDone)
+ throw new InvalidOperationException ("The RemapHandler method was called after the MapRequestHandler event occurred.");
+ Handler = handler;
+ }
+#endif
+
public void RewritePath (string path)
{
#if NET_2_0
#endif
void RewritePath (string filePath, string pathInfo, string queryString, bool setClientFilePath)
{
- filePath = UrlUtils.Combine (Request.BaseVirtualDir, filePath);
- if (!filePath.StartsWith (HttpRuntime.AppDomainAppVirtualPath))
- throw new HttpException (404, "The virtual path '" + filePath +
- "' maps to another application.");
+ if (filePath == null)
+ throw new ArgumentNullException ("filePath");
+ if (!VirtualPathUtility.IsValidVirtualPath (filePath))
+ throw new HttpException ("'" + HttpUtility.HtmlEncode (filePath) + "' is not a valid virtual path.");
+
+ bool pathRelative = VirtualPathUtility.IsAppRelative (filePath);
+ bool pathAbsolute = pathRelative ? false : VirtualPathUtility.IsAbsolute (filePath);
+ if (pathRelative || pathAbsolute) {
+ bool needSubstring = false;
+
+ if (pathRelative && filePath.Length > 1)
+ needSubstring = true;
+ string bvd = Request.BaseVirtualDir;
+ if (bvd.Length > 1)
+ bvd += "/";
+
+ string canonizedFilePath = VirtualPathUtility.Canonize (filePath);
+ filePath = VirtualPathUtility.Combine (bvd, needSubstring ? canonizedFilePath.Substring (2) : canonizedFilePath);
+ } else
+ filePath = VirtualPathUtility.Combine (VirtualPathUtility.GetDirectory (Request.FilePath), filePath);
+
+ if (!StrUtils.StartsWith (filePath, HttpRuntime.AppDomainAppVirtualPath))
+ throw new HttpException (404, "The virtual path '" + HttpUtility.HtmlEncode (filePath) + "' maps to another application.", filePath);
+
Request.SetCurrentExePath (filePath);
+ if (setClientFilePath)
+ Request.SetFilePath (filePath);
+
// A null pathInfo or queryString is ignored and previous values remain untouched
if (pathInfo != null)
Request.SetPathInfo (pathInfo);
if (queryString != null)
Request.QueryStringRaw = queryString;
-#if NET_2_0
- if (setClientFilePath)
- Request.SetFilePath (filePath);
-#endif
}
#region internals
set {
config_timeout = value;
+#if !TARGET_J2EE
+ if (timer != null) {
+ TimeSpan remaining = value - (DateTime.UtcNow - time_stamp);
+ long remaining_ms = Math.Max ((long)remaining.TotalMilliseconds, 0);
+
+ // See http://msdn2.microsoft.com/en-us/library/7hs7492w.aspx
+ if (remaining_ms > 4294967294)
+ remaining_ms = 4294967294;
+
+ timer.Change (remaining_ms, (long)Timeout.Infinite);
+ }
+#endif
}
}
- internal bool CheckIfTimeout (DateTime t)
- {
- if (Interlocked.CompareExchange (ref timeout_possible, 0, 0) == 0)
- return false;
-
- TimeSpan ts = t - time_stamp;
- return (ts > ConfigTimeout);
+#if !TARGET_J2EE
+ void TimeoutReached(object state) {
+ HttpRuntime.QueuePendingRequest (false);
+ if (Interlocked.CompareExchange (ref timeout_possible, 0, 0) == 0) {
+ timer.Change(2000, 0);
+ return;
+ }
+ StopTimeoutTimer();
+
+ thread.Abort (new StepTimeout ());
+ }
+
+ internal void StartTimeoutTimer() {
+ thread = Thread.CurrentThread;
+ timer = new Timer (TimeoutReached, null, (int)ConfigTimeout.TotalMilliseconds, Timeout.Infinite);
+ }
+
+ internal void StopTimeoutTimer() {
+ if(timer != null) {
+ timer.Dispose ();
+ timer = null;
+ }
}
internal bool TimeoutPossible {
{
Interlocked.CompareExchange (ref timeout_possible, 0, 1);
}
-#endregion
-
-#if NET_2_0
- Page last_page;
-
- internal Page LastPage {
- get {
- return last_page;
- }
-
- set {
- last_page = value;
- }
- }
#endif
+#endregion
+ }
+
+ class StepTimeout
+ {
}
}