Handling dynamic "folders" for url-rewrites?

  • Thread starter Thread starter Klaus Jensen
  • Start date Start date
K

Klaus Jensen

Hi

I created code to allow me to rewrite urls from global.asax, so that if the
incoming Url is for instance:

/Hats/ReallyCoolHat.aspx

....I look up ReallyCoolHat in the products table and rewrite the url to
Product.aspx?id=12 if that is the productId for ReallyCoolHat.

This works, because .aspx-files are handled by Asp.Net, so I can catch
requests in global.asax and rewrite the url, if I want to.

I also know how to set IIS to have Asp.Net handle all kinds of extensions...

But... I also need to do something similar for folders, ie...:

/Hats/

....But this does not have an file-extension, and is not handled by Asp.Net.

How do I make Asp.Net handle this, so I can catch requests to /Hats/ in
global.asax Application_beginrequest?
 
Hi

I created code to allow me to rewrite urls from global.asax, so that if the
incoming Url is for instance:

/Hats/ReallyCoolHat.aspx

...I look up ReallyCoolHat in the products table and rewrite the url to
Product.aspx?id=12 if that is the productId for ReallyCoolHat.

This works, because .aspx-files are handled by Asp.Net, so I can catch
requests in global.asax and rewrite the url, if I want to.

I also know how to set IIS to have Asp.Net handle all kinds of extensions...

But... I also need to do something similar for folders, ie...:

/Hats/

...But this does not have an file-extension, and is not handled by Asp.Net.

How do I make Asp.Net handle this, so I can catch requests to /Hats/ in
global.asax Application_beginrequest?

Hi...

Check out this
Scott Guthrie's post on url rewriting...
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

Thanks
Munna
www.kaz.com.bd
www.munnacs.110mb.com
 
"Peter said:
The bottom line for this "trick" is to create a wildcard ( * ) handler in IIS
that points to the aspnet_Isapi.dll which means that all requests without a
known file extension get sent throug ASP.NET, where you can process using
typical REGEX url-rewriting techniques.

The only problem with that is that it can put an unnecessary strain on
the server as *everything* is then sent through the ASP.NET engine.

Another solution is to create a Hats folde and add a default.aspx file
to it. This file does not need to do anything as the engine will
redirect to the real URL anyway, it's just there to get ASP.NEt to
process the request.

This is only practical if you have a smallish number of folders you want
to use. If you many, or if they change regularly, then this may not be
practical.

You could consider using URLs like /Hats_ReallyCoolHat.aspx which will
save you the hassle, and be better for the search engines as it looks
like a top-level folder instead of a second-level one like you
suggested.

HTH
 
Back
Top