// Author:
// Miguel de Icaza (miguel@novell.com)
// Gonzalo Paniagua Javier (gonzalo@novell.com)
+// Marek Habersack <mhabersack@novell.com>
//
//
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
using System.Web.SessionState;
using System.Web.UI;
using System.Web.Util;
-#if NET_2_0
+using System.Reflection;
using System.Collections.Generic;
using System.IO;
-using System.Reflection;
using System.Resources;
using System.Web.Compilation;
using System.Web.Profile;
using CustomErrorMode = System.Web.Configuration.CustomErrorsMode;
-#endif
-namespace System.Web {
+namespace System.Web
+{
// CAS - no InheritanceDemand here as the class is sealed
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- public sealed partial class HttpContext : IServiceProvider {
+ public sealed partial class HttpContext : IServiceProvider
+ {
internal HttpWorkerRequest WorkerRequest;
HttpApplication app_instance;
HttpRequest request;
Timer timer;
Thread thread;
bool _isProcessingInclude;
-
-#if NET_2_0
+
[ThreadStatic]
static ResourceProviderFactory provider_factory;
return default_provider_factory;
}
}
-#endif
public HttpContext (HttpWorkerRequest wr)
{
WorkerRequest = wr;
request = new HttpRequest (WorkerRequest, this);
response = new HttpResponse (WorkerRequest, this);
+#if NET_4_0
+ SessionStateBehavior = SessionStateBehavior.Default;
+#endif
}
public HttpContext (HttpRequest request, HttpResponse response)
{
this.request = request;
this.response = response;
-
+#if NET_4_0
+ SessionStateBehavior = SessionStateBehavior.Default;
+#endif
}
internal bool IsProcessingInclude {
internal bool IsCustomErrorEnabledUnsafe {
get {
-#if NET_2_0
CustomErrorsSection cfg = (CustomErrorsSection) WebConfigurationManager.GetSection ("system.web/customErrors");
-#else
- CustomErrorsConfig cfg = null;
- try {
- cfg = (CustomErrorsConfig) GetConfig ("system.web/customErrors");
- } catch {
- }
-
- if (cfg == null)
- return false;
-#endif
-
if (cfg.Mode == CustomErrorMode.On)
return true;
}
#if !TARGET_JVM
public bool IsDebuggingEnabled {
- get { return HttpRuntime.IsDebuggingEnabled; }
+ get { return RuntimeHelpers.DebuggingEnabled; }
}
#endif
public IDictionary Items {
}
}
-#if NET_2_0
internal bool MapRequestHandlerDone {
get;
set;
profile = value;
}
}
-#endif
public void AddError (Exception errorInfo)
{
errors = null;
}
-#if NET_2_0
[Obsolete ("use WebConfigurationManager.GetWebApplicationSection")]
-#endif
public static object GetAppConfig (string name)
{
object o = ConfigurationSettings.GetConfig (name);
return o;
}
-#if NET_2_0
[Obsolete ("see GetSection")]
-#endif
public object GetConfig (string name)
{
-#if NET_2_0
return GetSection (name);
-#else
- return WebConfigurationSettings.GetConfig (name, this);
-#endif
}
-#if NET_2_0
public static object GetGlobalResourceObject (string classKey, string resourceKey)
{
return GetGlobalResourceObject (classKey, resourceKey, Thread.CurrentThread.CurrentUICulture);
return true;
}
-
- internal static IResourceProvider GetResourceProvider (string key, bool isLocal)
+
+ internal static IResourceProvider GetResourceProvider (string virtualPath, bool isLocal)
{
if (!EnsureProviderFactory ())
return null;
// TODO: check if it makes sense to cache the providers and, if yes, maybe
// we should expire the entries (or just store them in InternalCache?)
IResourceProvider rp = null;
- if (!resource_providers.TryGetValue (key, out rp)) {
+ if (!resource_providers.TryGetValue (virtualPath, out rp)) {
if (isLocal)
- rp = provider_factory.CreateLocalResourceProvider (key);
+ rp = provider_factory.CreateLocalResourceProvider (virtualPath);
else
- rp = provider_factory.CreateGlobalResourceProvider (key);
+ rp = provider_factory.CreateGlobalResourceProvider (virtualPath);
if (rp == null) {
if (isLocal)
- rp = DefaultProviderFactory.CreateLocalResourceProvider (key);
+ rp = DefaultProviderFactory.CreateLocalResourceProvider (virtualPath);
else
- rp = DefaultProviderFactory.CreateGlobalResourceProvider (key);
+ rp = DefaultProviderFactory.CreateGlobalResourceProvider (virtualPath);
if (rp == null)
return null;
}
- resource_providers.Add (key, rp);
+ resource_providers.Add (virtualPath, rp);
}
return rp;
public static object GetGlobalResourceObject (string classKey, string resourceKey, CultureInfo culture)
{
- return GetGlobalObjectFromFactory (classKey, resourceKey, culture);
+ return GetGlobalObjectFromFactory ("Resources." + classKey, resourceKey, culture);
}
public static object GetLocalResourceObject (string virtualPath, string resourceKey)
{
return WebConfigurationManager.GetSection (name);
}
-#endif
+
object IServiceProvider.GetService (Type service)
{
if (service == typeof (HttpWorkerRequest))
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
RewritePath (path, true);
-#else
- RewritePath (path, false);
-#endif
}
public void RewritePath (string filePath, string pathInfo, string queryString)
RewritePath (filePath, pathInfo, queryString, false);
}
-#if NET_2_0
- public
-#else
- internal
-#endif
- void RewritePath (string path, bool rebaseClientPath)
+ public void RewritePath (string path, bool rebaseClientPath)
{
int qmark = path.IndexOf ('?');
if (qmark != -1)
- RewritePath (path.Substring (0, qmark), "", path.Substring (qmark + 1), rebaseClientPath);
+ RewritePath (path.Substring (0, qmark), String.Empty, path.Substring (qmark + 1), rebaseClientPath);
else
RewritePath (path, null, null, rebaseClientPath);
}
-#if NET_2_0
- public
-#else
- internal
-#endif
- void RewritePath (string filePath, string pathInfo, string queryString, bool setClientFilePath)
+ public void RewritePath (string filePath, string pathInfo, string queryString, bool setClientFilePath)
{
if (filePath == null)
throw new ArgumentNullException ("filePath");
bool pathRelative = VirtualPathUtility.IsAppRelative (filePath);
bool pathAbsolute = pathRelative ? false : VirtualPathUtility.IsAbsolute (filePath);
+ HttpRequest req = Request;
+ if (req == null)
+ return;
+
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 (pathRelative)
+ filePath = VirtualPathUtility.ToAbsolute (filePath);
+ } else
+ filePath = VirtualPathUtility.AppendTrailingSlash (req.BaseVirtualDir) + 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);
+
+ req.SetCurrentExePath (filePath);
+ req.SetFilePath (filePath);
+
if (setClientFilePath)
- Request.SetFilePath (filePath);
+ req.ClientFilePath = filePath;
// A null pathInfo or queryString is ignored and previous values remain untouched
if (pathInfo != null)
- Request.SetPathInfo (pathInfo);
+ req.SetPathInfo (pathInfo);
if (queryString != null)
- Request.QueryStringRaw = queryString;
+ req.QueryStringRaw = queryString;
}
-#region internals
+#if NET_4_0
+ public void SetSessionStateBehavior (SessionStateBehavior sessionStateBehavior)
+ {
+ SessionStateBehavior = sessionStateBehavior;
+ }
+#endif
+#region internals
internal void SetSession (HttpSessionState state)
{
session_state = state;
internal TimeSpan ConfigTimeout {
get {
if (config_timeout == null) {
-#if NET_2_0
HttpRuntimeSection section = (HttpRuntimeSection)WebConfigurationManager.GetSection ("system.web/httpRuntime");
config_timeout = section.ExecutionTimeout;
-#else
- HttpRuntimeConfig config = (HttpRuntimeConfig)
- GetConfig ("system.web/httpRuntime");
- config_timeout = new TimeSpan (0, 0, config.ExecutionTimeout);
-#endif
}
return (TimeSpan) config_timeout;
}
}
+#if NET_4_0
+ internal SessionStateBehavior SessionStateBehavior {
+ get;
+ private set;
+ }
+#endif
+
#if !TARGET_J2EE
void TimeoutReached(object state) {
HttpRuntime.QueuePendingRequest (false);