views:

236

answers:

3

if the user type

http://myweb/mysite.aspx (file does not exist)

I want them to go to

http://myweb/site.aspx (file does exist)

My goal is to make a bilingual website (including url) but without having to make physical file

this would be one file

http://myweb/acceuil.aspx
http://myweb/home.aspx
+1  A: 

That's not routing; that is a redirect.

_rick_shott seems to have the mojo on routing bad urls into a 301 redirect. I upvoted his answer. You should check out his HTTPModule solution.

Robert Harvey
with redirect, you have to create a file, I want to use the routing module so I wont have o do that
Fredou
Do you care about search engine optimization?
Robert Harvey
@Fredou: You don't have to create a file if you use an HTTPModule
Dan Esparza
+3  A: 

Not sure what you are trying to do, but this is the best turtorial for the question you asked:

How to: Use Routing with Web Forms

rick schott
Does this require the presence of the old page? If so, adding a simple script to the page solves that problem without a CustomRouteHandler. I think what he wants is a way to specify the old and new pages by name, without having to leave the old pages on the server.
Robert Harvey
I used the first url, "How to: Use Routing with Web Forms". You can remove everything else under it if you want. thanks
Fredou
A: 

In your web.config, add a customErrors and error node as follows:

    <customErrors mode="On" defaultRedirect="ErrorDisplayPage.aspx">
     <error statusCode="404" redirect="http://myweb/site.aspx"/&gt;
    </customErrors>

This will displayErrorDisplayPage.aspx for all unmanaged errors except for 404 errors (which are "page not found"). For 404 errors, the browser will redirect to the site.aspx page.

Jeff Siver
AFAIK this will redirect ALL 404's to the new page, unless this is in a location element. See http://msdn.microsoft.com/en-us/library/b6x6shw7(VS.71).aspx for more info.
Dan Esparza
Sorry, I thought that is what the poster was asking for - all not found pages to go to site.aspx.
Jeff Siver