Merge pull request #2530 from lambdageek/monoerror-mono_string_new
[mono.git] / mcs / class / System.Web / System.Web / HttpServerUtility.cs
index 939a3775303bda5accf376b6e859b4f0cfd6250d..9f94dcec23f85e2fef61c1f59fcbcdd426405967 100644 (file)
@@ -8,7 +8,7 @@
 //
 
 //
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2010 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
@@ -36,11 +36,12 @@ using System.Web.Util;
 using System.Collections.Specialized;
 using System.Security.Permissions;
 using System.Text;
+using System.Threading;
 using System.Web.Configuration;
 using System.Web.SessionState;
 
-namespace System.Web {
-
+namespace System.Web
+{
        //
        // Methods exposed through HttpContext.Server property
        //
@@ -88,19 +89,12 @@ namespace System.Web {
                        Execute (path, writer, true);
                }
 
-#if NET_2_0
                public void Execute (string path, bool preserveForm)
                {
                        Execute (path, null, preserveForm);
                }
-#endif
-               
-#if NET_2_0
-               public
-#else
-               internal
-#endif
-               void Execute (string path, TextWriter writer, bool preserveForm)
+
+               public void Execute (string path, TextWriter writer, bool preserveForm)
                {                       
                        Execute (path, writer, preserveForm, false);
                }
@@ -122,14 +116,9 @@ namespace System.Web {
 
                        string exePath = UrlUtils.Combine (context.Request.BaseVirtualDir, path);
                        bool cookieless = false;
-                       
-#if NET_2_0
-                       SessionStateSection config = WebConfigurationManager.GetSection ("system.web/sessionState") as SessionStateSection;
+                       SessionStateSection config = WebConfigurationManager.GetWebApplicationSection ("system.web/sessionState") as SessionStateSection;
                        cookieless = SessionStateModule.IsCookieLess (context, config);
-#else
-                       SessionConfig config = HttpContext.GetAppConfig ("system.web/sessionState") as SessionConfig;
-                       cookieless = config.CookieLess;
-#endif
+                       
                        if (cookieless)
                                exePath = UrlUtils.RemoveSessionId (VirtualPathUtility.GetDirectory (exePath), exePath);
                        
@@ -137,13 +126,13 @@ namespace System.Web {
                        Execute (handler, writer, preserveForm, exePath, queryString, isTransfer, true);
                }
 
-               internal void Execute (IHttpHandler handler, TextWriter writer, bool preserveForm, string exePath, string queryString, bool isTransfer, bool isInclude) {
-#if NET_2_0 && !TARGET_J2EE
+               internal void Execute (IHttpHandler handler, TextWriter writer, bool preserveForm, string exePath, string queryString, bool isTransfer, bool isInclude)
+               {
                        // If the target handler is not Page, the transfer must not occur.
                        // InTransit == true means we're being called from Transfer
-                       if (isTransfer && !(handler is Page))
-                               throw new HttpException ("Transfer is possible only to .aspx files");
-#endif
+                       bool is_static = (handler is StaticFileHandler);
+                       if (isTransfer && !(handler is Page) && !is_static)
+                               throw new HttpException ("Transfer is only allowed to .aspx and static files");
 
                        HttpRequest request = context.Request;
                        string oldQuery = request.QueryStringRaw;
@@ -167,9 +156,10 @@ namespace System.Web {
                        string oldExePath = request.CurrentExecutionFilePath;
                        bool oldIsInclude = context.IsProcessingInclude;
                        try {
-#if NET_2_0
                                context.PushHandler (handler);
-#endif
+                               if (is_static) // Not sure if this should apply to Page too
+                                       request.SetFilePath (exePath);
+
                                request.SetCurrentExePath (exePath);
                                context.IsProcessingInclude = isInclude;
                                
@@ -178,7 +168,9 @@ namespace System.Web {
                                } else {
                                        IHttpAsyncHandler asyncHandler = (IHttpAsyncHandler) handler;
                                        IAsyncResult ar = asyncHandler.BeginProcessRequest (context, null, null);
-                                       ar.AsyncWaitHandle.WaitOne ();
+                                       WaitHandle asyncWaitHandle = ar != null ? ar.AsyncWaitHandle : null;
+                                       if (asyncWaitHandle != null)
+                                               asyncWaitHandle.WaitOne ();
                                        asyncHandler.EndProcessRequest (ar);
                                }
                        } finally {
@@ -193,9 +185,8 @@ namespace System.Web {
                                response.SetTextWriter (previous);
                                if (!preserveForm)
                                        request.SetForm (oldForm);
-#if NET_2_0
+
                                context.PopHandler ();
-#endif
                                request.SetCurrentExePath (oldExePath);
                                context.IsProcessingInclude = oldIsInclude;
                        }
@@ -233,6 +224,23 @@ namespace System.Web {
                        return context.Request.MapPath (path);
                }
 
+               
+               public void TransferRequest (string path)
+               {
+                       TransferRequest (path, false, null, null);
+               }
+               
+               public void TransferRequest (string path, bool preserveForm)
+               {
+                       TransferRequest (path, preserveForm, null, null);
+               }
+
+               [MonoTODO ("Always throws PlatformNotSupportedException.")]
+               public void TransferRequest (string path, bool preserveForm, string method, NameValueCollection headers)
+               {
+                       throw new PlatformNotSupportedException ();
+               }
+               
                public void Transfer (string path)
                {
                        Transfer (path, true);
@@ -242,7 +250,7 @@ namespace System.Web {
                        Execute (path, null, preserveForm, true);
                        context.Response.End ();
                }
-#if NET_2_0
+
                public void Transfer (IHttpHandler handler, bool preserveForm)
                {
                        if (handler == null)
@@ -342,7 +350,6 @@ namespace System.Web {
                        }
                        return new string (chars);
                }
-#endif
 
                public string UrlDecode (string s)
                {