HttpModule not working to mimic subdirectories, what to do then ?

C

craigkenisston

Hi,

I'm writing an HttpModule in order to replace the parameters in the
aspx pages to look like subdirectories.

i.e. instead of having :
myexample.com/default.aspx?category=cat1&subcat=cat2
I want to have :
myexample.com/cat1/cat2/

While I was testing the functionality of HttpModule I was redirecting
from an ".aspx" file and it all was working fine.
Now that I switched to the real functionality, it just don't hit the
code.
I mean, the call to "myexample.com/cat1/cat2/" does not fire the
application request in my HttpModule.

Here is my code :

private void Application_BeginRequest(Object source,
EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
string myPath = context.Request.
ServerVariables["PATH_INFO"];

string[] strs = ExtractParams(myPath);
string vendor="";
string category="";
if (strs.Length == 2)
{
vendor = strs[0];
category = strs[1];
context.RewritePath("~/default.aspx?
vendor="+vendor+"&category"+category);
}


}

Now, if I put a break in the first line I see that the code is not even
hit when I have something like "myexample.com/cat1/cat2/". It was
working if I have "myexample.com/cat1.aspx".
I guess I need to configure something, somewhere to call this code when
calling an URL with directories.

Thanks in advance.
 
K

Karl Seguin

My guess is that the default in IIS isn't an aspx page (it's probably an
..html). Which means when people goto /cat1/cat2/ the request is actually
being passed to index.html which wouldn't get processed by ASP.net. you
need to change the default to default.aspx or something.

Karl
 
C

craigkenisston

I had several default documents in my configuration, I removed them all
and left "default.aspx" alone, after restarting everything I still
seeing the same behavior : files with extensions fire the
"begin_request", directories does not.

Have you seen this working ? I mean, is it supposed to work ?
I've seen sites doing this, with PHP or Perl, but not with Asp.Net.
Also, all asp.net samples about this techniques are using files, with
extension to do the mapping, never seen a sample with "/directories/".
 
R

Rick Strahl [MVP]

Hi Craig,

What exactly is your parser looking for?

I think what happens is that hte URL you're looking at will include
default.aspx in the Path Info, because that's what IIS translates it to...
Maybe that's causing you problems? IOW, you're going to get a different path
than just to path separators. You're going to get those plus Default.aspx
(ie. 3 parts).

+++ Rick ---

--

Rick Strahl
West Wind Technologies
www.west-wind.com
www.west-wind.com/weblog
 
C

craigkenisston

The parser is working fine. It does what I expect as long as I have
something like "/dir1/dir2.aspx". It does not work if I have
"/dir1/dir1/", because "Begin_request" is not being hit in this case.

After reading several dozens articles, I've got the conclusion that
what I'm trying to do requieres several tweaks :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/urlrewriting.asp

They told you'd have to create all the directories and put a default
document on it, if you want to allow people to look at them like
directories. They also says, that in order to avoid this, you'd need to
setup asp.net to handle all request, which would be a hard work.

So, I have to ask again, if somebody has seen this implementation, the
one where you can use "directories", like "/subdir1/subdir1/" in the
paths.
 
G

Guest

Hi Craig,

the problem is that you dont have an httphandler set to actually process the
request and render the page.

I have done something very similar which works well, from memory you need
to...

create an ihttphandlerfactory which in the GetHandler method calls

Web.UI.PageParser.GetCompiledPageInstance (very scarce documentation - I
don't think we are supposed to use it...)


in your IHttpModule you then need to set yourcontext.handler =
yourIHttpHandlerFactory.GetHandler(params....)
use this is to instatiate your template aspx page.


As I said this is from memory and there may have been a couple of other
steps... got to go into a meeting now but hopefully it will get you started

jd
 
G

Guest

followup: you also need to add a wildcard ISAPI mapping to the website in
IIS, make sure you remove the mapping from any sub folders wich serve images/
non processed docs or the aspnet engine will be used to serve them and it
will increase the load on the server.

HTH

jd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top