Переглянути джерело

* UrlUtils.cs: Some methods for working with session ids in
urls.

svn path=/trunk/mcs/; revision=20757

Jackson Harper 22 роки тому
батько
коміт
ad391da46e

+ 4 - 0
mcs/class/System.Web/System.Web.Util/ChangeLog

@@ -1,3 +1,7 @@
+2003-12-03  Jackson Harper <[email protected]>
+
+	* UrlUtils.cs: Some methods for working with session ids in urls.
+	
 2003-12-02  Gonzalo Paniagua Javier <[email protected]>
 
 	* WebEncoding.cs: use the Default encoding when the globalization

+ 39 - 1
mcs/class/System.Web/System.Web.Util/UrlUtils.cs

@@ -11,7 +11,8 @@
 
 using System;
 using System.Collections;
-using System.Text;
+using System.Text;
+using System.Web.SessionState;
 
 namespace System.Web.Util
 {
@@ -284,6 +285,43 @@ namespace System.Web.Util
 			}
 			return baseDir;
 		}
+
+		public static string GetFile (string url)
+		{
+			if(url == null)
+				return null;
+			if(url.Length == 0)
+				return String.Empty;
+			url.Replace ('\\', '/');
+
+			string file = url;
+			int last = url.LastIndexOf ('/');
+			if (last > 0)
+				file = url.Substring (last);
+			return file;
+		}
+
+		public static string InsertSessionId (string id, string path)
+		{
+			return Reduce (GetDirectory (path) + "/(" + id + ")/" + GetFile (path));
+		}
+
+		public static string GetSessionId (string path)
+		{
+			int len = path.Length;
+			if ((len < SessionId.IdLength + 2) || (path [len - 1] != ')') ||
+			    (path [len - SessionId.IdLength - 2] != '('))
+				return null;
+
+			return path.Substring (len - SessionId.IdLength - 1, SessionId.IdLength);
+		}
+
+		public static string RemoveSessionId (string base_path, string file_path)
+		{
+			int len = base_path.Length;
+			return Reduce (base_path.Substring (0, len - SessionId.IdLength - 2) + "/" +
+					GetFile (file_path));
+		}
 		
 		public static string ResolveVirtualPathFromAppAbsolute (string path)
 		{