Sunny Milenov
Sunny Milenov

Reputation: 22310

ASP.NET 404 (page not found) redirection with original parameters preserved

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.

Upvotes: 2

Views: 5994

Answers (4)

Astra
Astra

Reputation: 11221

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.

Upvotes: 1

John Rasch
John Rasch

Reputation: 63445

You could look into the UrlRewritingNet component.

Upvotes: 2

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114377

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.

Upvotes: 5

Igor Zelaya
Igor Zelaya

Reputation: 4277

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?

Upvotes: 0

Related Questions