bool isUserControl;
bool isApplication;
+ HttpContext context;
+
enum UserControlResult
{
OK = 0,
}
}
+ internal HttpContext Context {
+ get { return context; }
+ set { context = value; }
+ }
+
public void AddInterface (string iface)
{
if (interfaces == "") {
throw new ApplicationException ("Source file extension for controls " +
"must be .ascx");
- string srcLocation = PathUtil.Combine (null, src);
- UserControlData data = GenerateUserControl (srcLocation);
+ UserControlData data = GenerateUserControl (src, Context);
switch (data.result) {
case UserControlResult.OK:
prolog.AppendFormat ("\tusing {0};\n", "ASP");
}
}
+ private string GetTemplateDirectory ()
+ {
+ string templatePath = Path.GetDirectoryName (fullPath);
+ string appPath = Path.GetDirectoryName (HttpRuntime.AppDomainAppPath);
+
+ if (templatePath == appPath)
+ return "/";
+
+ templatePath = templatePath.Substring (appPath.Length);
+ if (Path.DirectorySeparatorChar != '/')
+ templatePath = templatePath.Replace (Path.DirectorySeparatorChar, '/');
+
+ return templatePath;
+ }
+
private void End ()
{
classDecl = "\tpublic class " + className + " : " + parent + interfaces + " {\n";
"\t\tprotected System.Web.HttpApplication ApplicationInstance\n\t\t{\n" +
"\t\t\tget { return (System.Web.HttpApplication) this.Context.ApplicationInstance; }\n" +
"\t\t}\n\n");
- //FIXME: add TemplateSourceDirectory: don't know what for...yet!
- //FIXME: it should be the path from the root where the file resides
+
constructor.AppendFormat (
"\t\tpublic override string TemplateSourceDirectory\n\t\t{{\n" +
"\t\t\tget {{ return \"{0}\"; }}\n" +
- "\t\t}}\n\n", Path.GetDirectoryName (fullPath)); // FIXME: should be rooted on .appVPath
+ "\t\t}}\n\n", GetTemplateDirectory ());
epilog.Append ("\n\t\tprotected override void FrameworkInitialize ()\n\t\t{\n" +
"\t\t\tthis.__BuildControlTree (this);\n");
public string assemblyName;
}
- private static UserControlData GenerateUserControl (string src)
+ private static UserControlData GenerateUserControl (string src, HttpContext context)
{
UserControlData data = new UserControlData ();
data.result = UserControlResult.OK;
- if (!File.Exists (src)) {
- data.result = UserControlResult.FileNotFound;
- return data;
- }
-
- UserControlCompiler compiler = new UserControlCompiler (new UserControlParser (src));
+ UserControlCompiler compiler = new UserControlCompiler (new UserControlParser (src, context));
Type t = compiler.GetCompiledType ();
if (t == null) {
data.result = UserControlResult.CompilationFailed;
+2002-12-18 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * AspGenerator.cs: now it uses the current HttpContext when creating
+ user controls. TemplateSourceDirectory is no longer a dummy value.
+
+ * GlobalAsaxCompiler.cs:
+ * PageCompiler.cs:
+ * UserControlCompiler.cs: set the context which will be used to locate
+ the files.
+
2002-12-13 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* AspGenerator.cs: added support for AutoEventWireup attribute in
{
string filename;
string sourceFile;
+ HttpContext context;
private GlobalAsaxCompiler (string filename)
{
}
}
- public static Type CompileApplicationType (string filename)
+ public static Type CompileApplicationType (string filename, HttpContext context)
{
CompilationCacheItem item = CachingCompiler.GetCached (filename);
if (item != null && item.Result != null) {
}
GlobalAsaxCompiler gac = new GlobalAsaxCompiler (filename);
+ gac.context = context;
return gac.GetCompiledType ();
}
AspParser parser = new AspParser (filename, input);
parser.Parse ();
AspGenerator generator = new AspGenerator (filename, parser.Elements);
+ generator.Context = context;
generator.BaseType = typeof (HttpApplication).ToString ();
generator.ProcessElements ();
string generated = generator.GetCode ().ReadToEnd ();
AspParser parser = new AspParser (inputFile, input);
parser.Parse ();
AspGenerator generator = new AspGenerator (inputFile, parser.Elements);
+ generator.Context = pageParser.Context;
generator.BaseType = pageParser.BaseType.ToString ();
generator.ProcessElements ();
pageParser.Text = generator.GetCode ().ReadToEnd ();
AspParser parser = new AspParser (inputFile, input);
parser.Parse ();
AspGenerator generator = new AspGenerator (inputFile, parser.Elements);
+ generator.Context = userControlParser.Context;
generator.BaseType = userControlParser.BaseType.ToString ();
generator.ProcessElements ();
userControlParser.Text = generator.GetCode ().ReadToEnd ();
//
// (C) 2002 Ximian, Inc. (http://www.ximian.com)
//
+
using System.IO;
using System.Web;
+using System.Web.Util;
namespace System.Web.UI
{
internal string MapPath (string path, bool allowCrossAppMapping)
{
- return context.Request.MapPath (path, baseVDir, allowCrossAppMapping);
+ if (context == null)
+ throw new HttpException ("context is null!!");
+
+ return context.Request.MapPath (path, BaseVirtualDir, allowCrossAppMapping);
}
internal string PhysicalPath (string path)
if (Path.DirectorySeparatorChar != '/')
path = path.Replace ('/', '\\');
- return Path.GetFullPath (Path.Combine (baseVDir, path));
+ return Path.GetFullPath (Path.Combine (BaseVirtualDir, path));
}
internal HttpContext Context
get {
return context;
}
+ set {
+ context = value;
+ }
}
internal string BaseDir
{
get {
if (baseDir == null)
- baseDir = MapPath (baseVDir, false);
+ baseDir = MapPath (BaseVirtualDir, false);
return baseDir;
}
internal string BaseVirtualDir
{
get {
+ if (baseVDir == null)
+ baseVDir = UrlUtils.GetDirectory (context.Request.FilePath);
+
return baseVDir;
}
}
+2002-12-18 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * BaseParser.cs: use MapPath and context to locate files.
+ * Control.cs: implemented MapPathSecure.
+ * TemplateControl.cs: use UrlUtils to generate the path.
+ * TemplateControlParser.cs: use the context and MapPath.
+ * UserControl.cs: implemented MapPath.
+ * UserControlParser.cs: added context parameter to constructor.
+
2002-12-17 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* Control.cs: implemented MapPathSecure.
[MonoTODO("Secure?")]\r
protected string MapPathSecure(string virtualPath)\r
{\r
- return Context.Request.MapPath (virtualPath);\r
+ string combined = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);\r
+ return Context.Request.MapPath (combined);\r
}\r
\r
protected virtual bool OnBubbleEvent(object source, EventArgs args) //DIT\r
if (virtualPath == null)
throw new ArgumentNullException ("virtualPath");
- if (virtualPath [0] == '/')
- throw new ArgumentException ("Path cannot be rooted", "virtualPath");
-
- virtualPath = PathUtil.Combine (TemplateSourceDirectory, virtualPath);
-
- return UserControlCompiler.CompileUserControlType (new UserControlParser (virtualPath));
+ string vpath = UrlUtils.Combine (TemplateSourceDirectory, virtualPath);
+ return UserControlCompiler.CompileUserControlType (new UserControlParser (vpath, Context));
}
public Control LoadControl (string virtualPath)
using System.Collections;
using System.IO;
using System.Web.Compilation;
+using System.Web.Util;
namespace System.Web.UI
{
{
internal object GetCompiledInstance (string virtualPath, string inputFile, HttpContext context)
{
- InputFile = inputFile;
+ Context = context;
+ InputFile = MapPath (virtualPath);
Type type = CompileIntoType ();
if (type == null)
return null;
FrameworkInitialize ();
}
- [MonoTODO]
public string MapPath (string virtualPath)
{
- throw new NotImplementedException ();
+ return Request.MapPath (virtualPath, TemplateSourceDirectory, true);
}
protected override void LoadViewState (object savedState)
{
public sealed class UserControlParser : TemplateControlParser
{
- internal UserControlParser (string inputFile)
+ internal UserControlParser (string inputFile, HttpContext context)
{
- InputFile = inputFile;
+ Context = context;
+ InputFile = context.Request.MapPath (inputFile);
}
public static Type GetCompiledType (string virtualPath, string inputFile, HttpContext context)
{
- UserControlParser ucp = new UserControlParser (inputFile);
+ UserControlParser ucp = new UserControlParser (inputFile, context);
Type t = ucp.CompileIntoType ();
return t;
}
+2002-12-18 Gonzalo Paniagua Javier <gonzalo@ximian.com>\r
+\r
+ * PathUtil.cs: removed.\r
+ * UrlUtils.cs: fixed Combine to handle '~'.\r
+\r
2002-12-12 Gonzalo Paniagua Javier <gonzalo@ximian.com>\r
\r
* PathUtil.cs: some path handling methods that are not available in\r
+++ /dev/null
-//
-// System.Web.Util.PathUtil
-//
-// Authors:
-// Gonzalo Paniagua Javier (gonzalo@ximian.com)
-//
-// (C) 2002 Ximian, Inc (http://www.ximian.com)
-//
-
-using System;
-using System.Collections;
-using System.IO;
-using System.Reflection;
-
-namespace System.Web.Util
-{
- internal class PathUtil
- {
- static string appbase;
- static char [] separators;
-
- static PathUtil ()
- {
- // This hack is a workaround until AppDomainVirtualPath works... Gotta investigate it.
- Assembly entry = Assembly.GetEntryAssembly ();
- appbase = Path.GetDirectoryName (entry.Location);
- //
-
- if (Path.DirectorySeparatorChar != Path.AltDirectorySeparatorChar)
- separators = new char [] {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar};
- else
- separators = new char [] {Path.DirectorySeparatorChar};
- }
-
- static string MakeAbsolute (string abspath)
- {
- string [] parts = abspath.Split (separators);
- ArrayList valid = new ArrayList ();
-
- int len = parts.Length;
- bool hasDots = false;
- for (int i = 0; i < len; i++) {
- if (parts [i] == ".") {
- hasDots = true;
- continue;
- }
-
- if (parts [i] == "..") {
- hasDots = true;
- if (valid.Count > 0)
- valid.RemoveAt (valid.Count - 1);
- continue;
- }
-
- valid.Add (parts [i]);
- }
-
- if (!hasDots)
- return abspath;
-
- parts = (String []) valid.ToArray (typeof (string));
- string result = String.Join (new String (Path.DirectorySeparatorChar, 1), parts);
- if (!Path.IsPathRooted (result))
- return Path.DirectorySeparatorChar + result;
-
- return result;
- }
-
- static public string Combine (string basepath, string relative)
- {
- if (relative == null || relative.Length == 0)
- throw new ArgumentException ("empty or null", "relative");
-
- char first = relative [0];
- if (first == '/' || first == '\\' || Path.IsPathRooted (relative))
- throw new ArgumentException ("'relative' is rooted", "relative");
-
- if (first == '~' && relative.Length > 1 && Array.IndexOf (separators, relative [1]) != -1)
- return Path.Combine (appbase, relative.Substring (2));
-
- if (basepath == null)
- basepath = appbase;
-
- return MakeAbsolute (Path.Combine (basepath, relative));
- }
- }
-}
-
\r
public static void FailIfPhysicalPath(string path)\r
{\r
- if(path!= null && path.Length > 0)\r
+ if(path!= null && path.Length > 1)\r
{\r
- if(path[0]==':' || path.StartsWith(@"\\"))\r
+ if(path[1]==':' || path.StartsWith(@"\\"))\r
throw new HttpException(HttpRuntime.FormatResourceString("Physical_path_not_allowed", path));\r
}\r
}\r
\r
- public static string Combine(string basePath, string relPath)\r
+ public static string Combine (string basePath, string relPath)\r
{\r
- FailIfPhysicalPath(relPath);\r
- if(IsRootUrl(relPath))\r
- {\r
- if(relPath != null && relPath.Length > 0)\r
- {\r
- return Reduce(relPath);\r
- }\r
+ FailIfPhysicalPath (relPath);\r
+ if (IsRootUrl (relPath)) {\r
+ if (relPath != null && relPath.Length > 0)\r
+ return Reduce (relPath);\r
+\r
return String.Empty;\r
}\r
- if(relPath.Length < 3 || relPath[0]!='~' || (relPath[0]!='/' && relPath[0]!='\\'))\r
- {\r
- if(basePath==null || basePath.Length==1 || basePath[0]=='/')\r
+\r
+ if (relPath.Length < 3 || relPath [0] != '~' || relPath [0] == '/' || relPath [0] == '\\') {\r
+ if (basePath == null || basePath.Length == 1 || basePath [0] == '/')\r
basePath = String.Empty;\r
- return Reduce(basePath + "/" + relPath);\r
+\r
+ return Reduce (basePath + "/" + relPath);\r
}\r
+\r
string vPath = HttpRuntime.AppDomainAppVirtualPath;\r
- if(vPath.Length <= 1)\r
+ if (vPath.Length <= 1)\r
vPath = String.Empty;\r
- return Reduce(vPath + "/" + relPath.Substring(2));\r
+\r
+ return Reduce (vPath + "/" + relPath.Substring (2));\r
}\r
\r
public static bool IsValidProtocol(string protocol)\r
+2002-12-18 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * HttpApplicationFactory.cs: add the context as parameter when building
+ the application Type.
+
+ * HttpCookie.cs: new internal constructor.
+ * HttpCookieCollection.cs: new internal method to make a cookie expire.
+
+ * HttpRequest.cs: MapPath fixes.
+ * HttpResponse.cs: implemented ApplyAppPathModifier.
+ * HttpRuntime.cs: fixed typo in AppDomainAppVirtualPath.
+
2002-12-17 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* HttpContext.cs: hack to create a default user when there's no one.
if (File.Exists(_appFilename)) {\r
// Setup filemonitor for all filedepend also. CacheDependency?\r
\r
- _appType = GlobalAsaxCompiler.CompileApplicationType (_appFilename);\r
+ _appType = GlobalAsaxCompiler.CompileApplicationType (_appFilename, context);\r
if (_appType == null)\r
throw new ApplicationException ("Error compiling application file (global.asax).");\r
} else {\r
_Path = "/";
}
+ internal HttpCookie (string name, string value, string path, DateTime expires)
+ {
+ _Name = name;
+ _Value = value;
+ _Path = path;
+ if (expires != DateTime.MinValue)
+ Expires = expires;
+ }
+
internal HttpResponseHeader GetCookieHeader ()
{
StringBuilder oSetCookie = new StringBuilder ();
if (null != _Response)
_Response.ChangedCookieColl();
}
+
+ internal void MakeCookieExpire (string name, string path)
+ {
+ DateTime expirationTime = new DateTime (1999, 10, 12); // This is the date MS sends!
+ HttpCookie willExpire = new HttpCookie (name, String.Empty, path, expirationTime);
+ Remove (name);
+ Add (willExpire);
+ }
}
}
private HttpBrowserCapabilities _browser;\r
\r
private HttpCookieCollection cookies;\r
+ private bool rewritten;\r
\r
public HttpRequest(string Filename, string Url, string Querystring) {\r
_iContentLength = -1;\r
\r
public string PhysicalPath {\r
get {\r
- if (null != _WorkerRequest) {\r
- _sPathTranslated = _WorkerRequest.GetFilePathTranslated();\r
- if (null == _sPathTranslated) {\r
- _sPathTranslated = _WorkerRequest.MapPath(FilePath);\r
- }\r
+ if (_sPathTranslated == null && _WorkerRequest != null) {\r
+ if (rewritten)\r
+ _sPathTranslated = _WorkerRequest.GetFilePathTranslated ();\r
+\r
+ if (null == _sPathTranslated)\r
+ _sPathTranslated = _WorkerRequest.MapPath (FilePath);\r
}\r
\r
return _sPathTranslated;\r
}\r
}\r
\r
+ internal string RootVirtualDir {\r
+ get {\r
+ if (_sRequestRootVirtualDir == null) {\r
+ _sRequestRootVirtualDir = FilePath;\r
+ int pos = _sRequestRootVirtualDir.LastIndexOf ('/');\r
+ if (pos == -1 || pos == 0)\r
+ _sRequestRootVirtualDir = "/";\r
+ else\r
+ _sRequestRootVirtualDir = _sRequestRootVirtualDir.Substring (0, pos);\r
+ }\r
+\r
+ return _sRequestRootVirtualDir;\r
+ }\r
+ }\r
+ \r
public byte [] BinaryRead(int count) {\r
int iSize = TotalBytes;\r
if (iSize == 0) {\r
return arrRet;\r
}\r
\r
- public string MapPath(string VirtualPath)\r
+ public string MapPath (string VirtualPath)\r
{\r
- if (_sRequestRootVirtualDir == null) {\r
- _sRequestRootVirtualDir = FilePath;\r
- int pos = _sRequestRootVirtualDir.LastIndexOf ('/');\r
- if (pos == -1 || pos == 0)\r
- _sRequestRootVirtualDir = "/";\r
- else\r
- _sRequestRootVirtualDir = _sRequestRootVirtualDir.Substring (0, pos);\r
- }\r
- return MapPath (VirtualPath, _sRequestRootVirtualDir, true);\r
+ return MapPath (VirtualPath, RootVirtualDir, true);\r
}\r
\r
- [MonoTODO]\r
- public string MapPath(string virtualPath, string baseVirtualDir, bool allowCrossAppMapping)\r
+ [MonoTODO("allowCrossAppMapping?")]\r
+ public string MapPath (string virtualPath, string baseVirtualDir, bool allowCrossAppMapping)\r
{\r
if (_WorkerRequest == null)\r
throw new HttpException ("No HttpWorkerRequest!!!");\r
\r
if (virtualPath == null || virtualPath.Length == 0)\r
virtualPath = ".";\r
+ else\r
+ virtualPath = virtualPath.Trim ();\r
+\r
+ if (System.IO.Path.DirectorySeparatorChar != '/')\r
+ virtualPath = virtualPath.Replace (System.IO.Path.DirectorySeparatorChar, '/');\r
+\r
+ if (UrlUtils.IsRooted (virtualPath)) {\r
+ virtualPath = UrlUtils.Reduce (virtualPath);\r
+ } else {\r
+ if (baseVirtualDir == null)\r
+ virtualPath = UrlUtils.Combine (RootVirtualDir, virtualPath);\r
+ else\r
+ virtualPath = UrlUtils.Combine (baseVirtualDir, virtualPath);\r
+ }\r
\r
- virtualPath = System.IO.Path.Combine (baseVirtualDir, virtualPath);\r
return _WorkerRequest.MapPath (virtualPath);\r
}\r
\r
if (_Cookies != null) {
int length = _Cookies.Count;
- for (int i = 0; i < length; i++)
+ for (int i = 0; i < length; i++) {
oHeaders.Add (_Cookies.Get (i).GetCookieHeader ());
+ }
}
return oHeaders;
throw new NotImplementedException ();
}
- [MonoTODO()]
public string ApplyAppPathModifier (string virtualPath)
{
- throw new NotImplementedException ();
+ if (virtualPath == null)
+ return null;
+
+ if (UrlUtils.IsRelativeUrl (virtualPath)) {
+ virtualPath = UrlUtils.Combine (_Context.Request.RootVirtualDir, virtualPath);
+ } else if (UrlUtils.IsRooted (virtualPath)) {
+ virtualPath = UrlUtils.Reduce (virtualPath);
+ }
+
+ return virtualPath;
}
public bool Buffer
Clear ();
+ url = ApplyAppPathModifier (url);
StatusCode = 302;
AppendHeader (HttpWorkerRequest.HeaderLocation, url);
public static string AppDomainAppVirtualPath {
get {
if (appDomainAppVirtualPath == null)
- appDomainAppPath = (string) AppDomain.CurrentDomain.GetData (".appVPath");
+ appDomainAppVirtualPath = (string) AppDomain.CurrentDomain.GetData (".appVPath");
return appDomainAppVirtualPath;
}
System.Web.Util/FilePathParser.cs
System.Web.Util/IISVersionInfo.cs
System.Web.Util/NativeFileChangeEventHandler.cs
-System.Web.Util/PathUtil.cs
System.Web.Util/UrlUtils.cs
System.Web.Util/WebEncoding.cs
System.Web.Util/WebEqualComparer.cs