Welcome to WebmasterWorld Guest from 54.164.198.240

Forum Moderators: ocean10000

Message Too Old, No Replies

Latest ASP.NET URL rewrite thinking

How best to go about it?

     
7:25 pm on Sep 26, 2005 (gmt 0)

New User

10+ Year Member

joined:May 17, 2005
posts:37
votes: 0


I know there has been a lot written about this topic, but the final answer eludes me despite much research.

The scenario:

IIS, ASP.NET, Database with approx 100,000 records. Each record creates its own dynamic page, but with a dirty URL. How best to clean the URLs so that the spiders can index them easily?

But the solution MUST be applicable to our scenario:

1. The URLs must be of the form http://www.example.com/member/1023 (that is, no ".aspx", ".asp" or any other extension)
2. We DO have access to IIS as this is our own server.
3. We DON'T want to install a third party component. We want to install something we can modify ourselves. Probably in the global.asax file using the RewritePath functionality.
4. We DON'T want to map ALL files to be handled by the .net engine.
5. We DON'T want to use a "404" type solution because the 404 page would get loaded up with too much code. We want to separate out each type of page into it's own file.

So, can anybody shed any light on the latest thinking on this? All the solutions and articles I have found online either rely on the URL having a .aspx extension, or installing third party software.

Many thanks, Gordon.

[edited by: Xoc at 12:25 am (utc) on Oct. 27, 2005]
[edit reason] changed to use example.com [/edit]

11:37 pm on Sept 26, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 24, 2005
posts:965
votes: 0


You don't seem to be making sense to me. You don't want to put the code as a seperate 404 handler because it would supposedly create too much code, but you don't mind putting it in global.asax, I can't really see how that's going to create less code.

I guess you're going to need a lot of aspx files and a lot of Server.Transfer statements. I wish you the best of luck trying to maintain it all in the years to come ;-)

If it were me, I'd use ISAPI rewrite. fast, Easy, flexible and maintinable, but obviously that's not masochistic enough for you!

6:10 pm on Sept 27, 2005 (gmt 0)

New User

10+ Year Member

joined:May 17, 2005
posts:37
votes: 0


Sorry for not making myself clear.

Thanks for the suggestion regarding ISAPI rewrite, but that is a third party component and as I mentioned we don't want to use one.

We don't want to use a 404 based solution so unfortunately that is out.

We can insert a few lines of code into the global.asax file, no problems there.

Could you explain what your proposed solution using Server.Transfer is about? I have not heard of this being used for a production level solution.

Thanks, G.

7:55 pm on Sept 27, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 30, 2003
posts:374
votes: 0


If all of your files are aspx to begin with and you only want to change the way the URL is displayed, use an ASP.Net HTTPHandler. You build it yourself so it is not 3rd party.
10:20 am on Sept 28, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Apr 29, 2003
posts:123
votes: 0


I did it in the Application_BeginRequest in global.asax. I inspect each url and rewrite it appropriately if necesary using regex. Its only about 15 lines of code as the format of the rewriting is the same for most pages.

Only possible gotcha is you need to use RewritePath again to point to the original URL in the destination page, during the Page_Load event if your form posts back to the server.

The site is quite small (100 pages) so maybe it wouldnt be scaleable? I'm no expert so I'm not sure if this is a good way to do it but it works for me.

3:53 pm on Sept 28, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Feb 18, 2003
posts:629
votes: 0


To do it the way you want to there is 1 catch - you need to put an index file into each fake directory otherwise IIS is going to barf. Once you do that you can use scott mitchells redirect examples.

If you need help just ask - I did this for a client on a shared hosting account so we didn't have access to anything powerful in IIS either.

3:57 pm on Sept 28, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Feb 18, 2003
posts:629
votes: 0


Here's how I did it.

When a "member" is created I create a folder from them and do a quick copy of a blank index.aspx into that folder.

I then use Scott Mitchells rewriter app to do the following:

1) Parse all text after "members/" using a regex. Put that text into a variable.

2) Redirect to showmembers.aspx?id={text from step 1}

All the user ever sees is site.com/members/1023 but they're actually at showmembers.aspx?id=1023 All it actually takes is a few lines in web.config once you get the urlrewriter in.

8:26 pm on Sept 28, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 30, 2003
posts:374
votes: 0


HttpModule for URL rewriting:

[15seconds.com...]

12:25 pm on Sept 29, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 24, 2005
posts:965
votes: 0


Nice article Nige,

However, a question to GordonS, I'm still utterly confused by this.

The code is the same length whether you use the 404 handler or the HTTPHandler. So why is a 404 solution preferable to a global.asax solution?