[Mono-list] Rewriting path with an HttpModule

Gonzalo Paniagua Javier gonzalo@ximian.com
18 Mar 2003 01:07:27 +0100


El lun, 17 de 03 de 2003 a las 14:42, Daniel Lopez escribió:
> As mentioned earlier, I am developing an ASP.NET HttpModule that maps URLs like
> 
> ~/username/foo/bar.aspx

/~username/....

Well, in this case, the application host running the module must be
running on '/' virtual directory, since MS does not allow that the path
passed to HttpContext.RewritePath is from another application (i just
tested it under MS+IIS and it says "The virtual path 'xxx' maps to
another application, which is not allowed" (btw, i'll change RewritePath
to behave as MS after some more testing)).

> 
> to the file on disk
> 
> /home/username/public_html/foo/bar.aspx
> 
> In a similar way to how Apache mod_userdir does.
> That requires implementing RewritePath and changing the PhysicalFilePath
> returned, small changes that I already commited.
> The problem that I am running into is that some parts of the current codebase
> assume that that file path does not change in the life of the request and
> that is also rooted on AppPath.

There are probably a few fields returned from properties that are filled
on the first use of the property. Those fields have to be set to null in
RewritePath. I'll try to fix this too.

> I am looking for the minimal changes to get this to work, I attach a small
> pacth that works, but since I am not familiar with that part of the
> codebase, can you have a look before I apply?

The path passed to rewrite path must be relative to the application host
base path (--root in server.exe), so UserDir.cs is wrong because it
passes the full path to the file instead of a virtual path. (MS says
"c:\xxx" is a physical path") (heh, and they say that they throw an
ArgumentNullException when the path is null but i get a
NullReferenceException :).

I don't think that hacking the generator is a good idea. For example,
the developer can provide his/her own .dll with a
TemplateSourceDirectory override.

> 
> I also attach the sample module and a makefile. To test this, you will
> need to copu UserDir.dll to where your other dlls are and add the following
> to your machine.config in the <httpModules> section 
> 
> <add name="UserDir" type="ModMono.Examples.UserDir, UserDir" />

After fixing RewritePath, i'll modify it and send it back to you.

Btw, I've found an interesing link (god bless google!):
http://www.codeproject.com/aspnet/URLRewriter.asp 


Thanks!

-Gonzalo