views:

1804

answers:

4

I'm replacing an old web application with a new one, with different structure.

I can not change the virtual directory path for the new app, as I have users which have bookmarked different links to the old app.

Lets say I have a user, who has this bookmark:

http://server/webapp/oldpage.aspx?data=somedata

My new app is going to reside in the same virtual directory, replacing the old one, but it has no longer oldpage.aspx, instead it has different layout, but it still needs the parameter from the old url.

So, I have set to redirect 404 errors to redirectfrombookmark.aspx, where I decide how to process the request.

The problem is, that the only parameter I receive is "aspxerrorpath=/webapp/oldpage.aspx", but not the "data" parameter, and I need it to correctly process the request.

Any idea how I can get the full "original" url in the 404 handler?

EDIT: reading the answers, looks like I did not make the question clear enough:

  1. The users have bookmarked many different pages (oldpage1, oldpage2, etc.) and I should handle them equally.
  2. The parameters for each old page are almost the same, and I need a specific ones only.
  3. I want to re-use the "old" virtual directory name for the "new" application.
  4. The search bots, etc., are not a concern, this is internal application with dynamic content, which expires very often.

The question is - can I do this w/o creating a bunch of empty pages in my "new" application with the old names, and Request.Redirect in their OnLoad. I.e. can this be done using the 404 mechanism, or some event handling in Global.asax, etc.

A: 

POST and GET parameters are only available per request. If you already know the name of the old page (OldPage.aspx) why not just add there a custom redirect in it?

Igor Zelaya
thanks, see the latest change in the question.
Sunny
+3  A: 

For the purposes of SEO, you should never redirect on a 404 error. A 404 should be a dead-end, with some helpful information of how to locate the page you're looking for, such a site map.

You should be using a 301, moved permanently. This allows the search bots to update their index without losing the page rank assigned to the original page,

See: http://www.webconfs.com/how-to-redirect-a-webpage.php on how to code this type of response.

Diodeus
thanks, see the latest change in the question.
Sunny
+1  A: 

You should also look into using some of the events in your Global.ascx(?extention) file to check for errors and redirect intelligently. The OnError event is what you want to work with. You will have the variables from the request at that point in time (under the HttpContext object) and you can have your code work there instead of a 404. If you go this route, be sure you redirect the 404 correctly for anything other than oldpage.aspx.

I am sorry I don't have any explicit examples or information right now, hopefully this will point you in the right direction.

Redbeard 0x0A
thanks, see the latest change in the question.
Sunny
I agree, handling the error in the Global.asax OnError would do the trick - catch the error, check that it's a 404, work out where you should be going, and redirect (using a 301, so not Response.Redirect) as required. Anything you can't handle, you can return a 404 as before.
Zhaph - Ben Duguid
+2  A: 

You could look into the UrlRewritingNet component.

John Rasch
this looks like a good option. thanks.
Sunny
UrlRewriting (aka mod_rewrite) has been a long time favorite for solving this problem on Apache, so getting a tool for IIS to do the same thing would also be a good choice.
Redbeard 0x0A