467,895 Members | 1,449 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,895 developers. It's quick & easy.

Handling dynamic "folders" for url-rewrites?

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?

Jun 30 '07 #1
  • viewed: 1733
Share:
4 Replies
On Jul 1, 5:29 am, "Klaus Jensen" <spammers...@fromcancer.comwrote:
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/archi...h-asp-net.aspx

Thanks
Munna
www.kaz.com.bd
www.munnacs.110mb.com

Jul 1 '07 #2
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.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"Klaus Jensen" wrote:
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?

Jul 1 '07 #3
In article <62**********************************@microsoft.co m>, "Peter
Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrites
>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
>-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"Klaus Jensen" wrote:
>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?

--
Alan Silver
(anything added below this line is nothing to do with me)
Jul 8 '07 #4
As another alternative, you can map the 404 handler in IIS to 404.aspx where
you can do urlrewriting based on urls like "http://mysite/user/joshmoe" -
with no extension. I haven't tested this for performance, but it does work -
IIS will call the 404.aspx page and append the requested "bogus" url onto the
querystring.
Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"Alan Silver" wrote:
In article <62**********************************@microsoft.co m>, "Peter
Bromberg [C# MVP]" <pb*******@yahoo.yabbadabbadoo.comwrites
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
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"Klaus Jensen" wrote:
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?


--
Alan Silver
(anything added below this line is nothing to do with me)
Jul 8 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Konrad L. M. Rudolph | last post: by
235 posts views Thread by napi | last post: by
4 posts views Thread by Larry R Harrison Jr | last post: by
1 post views Thread by Krazitchek | last post: by
9 posts views Thread by Clinton Frankland | last post: by
2 posts views Thread by Johnny Meredith | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.