[Mono-list] Rewriting path with an HttpModule
Gonzalo Paniagua Javier
gonzalo@ximian.com
23 Mar 2003 03:12:45 +0100
El sáb, 22 de 03 de 2003 a las 21:22, Daniel Lopez escribió:
> > > After fixing RewritePath, i'll modify it and send it back to you.
> >
> > Mmm. Well, as RewritePath is more of a 'hide the real URL' thing, and
> > after some thinking, I bet for adding the ~user stuff in
> > MonoWorkerRequest.
>
> I think it could be done with
>
> 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).
I think that you can only map it to the / root virtual directory.
> > Why? There's one place where you can fake the real path to the file
> > (MapPath), so you can map "/~gonzalo/" to the file
> > "/home/gonzalo/public_html/index.aspx" or even using a configuration
> > file like the one in the link I put in my previous mail.
>
> 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?
> 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.
-Gonzalo