[Mono-list] Rewriting path with an HttpModule
Daniel Lopez
daniel@rawbyte.com
Mon, 24 Mar 2003 12:04:52 -0800
> > MonoApplication /~ /home
>
> No. At least if we want to be compatible with MS runtime...
> If /~ is the root virtual directory, /~user is not in that virtual
> directory (while /~/user is under that directory).
Yes, you are right :)
> > We can modify Request to support user directories, but it may be better to
> > create a hook point in MapPath(), that allows you to have arbitrary code
> > providing that functionality.
> > What I have in mind is a module that runs the mapped path thru Apache API
> > and then takes a look at the resulting path_translated filed in the
> > request_rec structure. This would allow us to reuse all the existing Apache
> > modules that map virtual paths to physical paths, such as mod_userdir or
> > mod_rewrite.
> > That would require that:
> >
> > a) All MapPath functions eventually call Request.MapPath() (I did some
> > greping and think that is the case)
>
> Yes.
>
> May be we can add a 'MapPathEvent' event to MonoWorkerRequest. Then, in
> MapPath we do something like:
> if (MapPathEvent != null) {
> MapPathEventArgs args = new MapPathEventArgs (path);
> MapPathEventHandler [] evts = (MapPathEventHandler)
> MapPathEvent.GetInvocationList ();
> foreach (MapPathEventHandler evt in evts) {
> evt (this, args);
> if (args.MappedPath != null)
> return args.MappedPath;
> }
> }
> // Here goes the current code
>
> This way we can register any possible path 'mapper' method adding it to
> MapPathEvent. If there is one of those 'mappers' that recognizes the
> path and map it to a real path (ie, sets MappedPath), we return that
> path.
>
> What do you think?
Yes, that was I had in mind, maybe even integrating with teh
rest of events (BeginRequest, etc.)
> > b) Other parts of the code do not make assumptions that physical paths are
> > rooted in the Application physical path, as for example happens in
> > mcs/class/System.Web/System.Web.Compilation/AspGenerator.cs
> > See patch in
> > http://lists.ximian.com/archives/public/mono-list/2003-March/012992.html
>
> templatePath should be the absolute virtual directory of the file being
> processed. That's not a file system path. It's used to look for other
> files referred from the one being processed.
Exactly :) What I am saying is that, in order to get that virtual path,
GetTemplateDirectory() it substracts two physical directory paths, the one
containing the file and the AppDomainAppPath. That assumes that they have a
common initial part. This is true currently, but if you introduce a mapping
function that maps to arbitrary files then it is not. Thatīs why I had to
patch it (though I dont know if the change I introduced was the right one)
Cheers
Daniel