views:

426

answers:

5

We have a website; which, till now had only HTML pages. Now we are redeveloping it in ASP .Net.

This means that all the .html pages will be changed to .aspx extension. The problem is, there are a lot of external references to these pages, and we dont want to go and chage each and every link to aspx right away.

Is there any way to redirect a link to .html pages to .aspx pages? For example, is there any way that the server checks the file specified, finds out that it links to .html page and automatically opens the .aspx page?

+1  A: 

if you do some sort of url rewriting you can have all the links stay the same and just serve up the aspx pages, request for index.html gets mapped to index.aspx

here's what ms says about asp.net url rewriting:

http://msdn.microsoft.com/en-us/library/ms972974.aspx

John Boker
Can you elaborate a bit? I apologize but I am a beginner. :)
nullDev
just added a link, basically all requests are intercepted and you decide what to serve.
John Boker
+2  A: 

I would take this opportunity to leave extensions (.html, .aspx, etc) behind.

For all our major websites we now use a custom mapping system, whereby a virtual page URI is mapped to a specific .aspx (or.html) page. This has a few benefits:

  • Your visitors see "nicer" URIs;
  • You're free to re-organise your site as you see fit, behind the scenes, without breaking existing incoming links;
  • You can use dynamic virtual URIs, eg instead of /Product.aspx?p=Blah, you can use /Products/Blah

We have our own custom system, but I believe ASP.NET MVC now has this feature built-in.

(If you go down this route, you can add legacy mappings for .html URIs that point to your new .aspx pages).

stusmith
A: 

Here's how we handled a similar situation.

  1. Setup IIS to map html extension to ASP.Net instead of handling it directly.

  2. In the HttpApplication.BeginRequest handler see if the request is being made for a html file that has been migrated to aspx if so then serve out the aspx page instead by redirecting the response.

  3. In case the html fiile hasn't been mapped yet just serve out the static html file.

Sijin
A: 

Like stusmith touched on, you should not let your underlying technology be exposed (and certainly not mandate) what your URIs look like. The best way is as mentioned to not show any extensions at all, but in the current situation maybe it is possible to configure the system in such a way that .html files are acted upon as if they were .aspx?

I don't know the first thing about .NET but I assume that this is possible without having to go through too many hoops.

The second best approach is to rewrite the URIs, but that requires extra work for the server (not much, but it adds up).

(Don't redirect with a meta refresh. Every other solution is better.)

Berserk
+1  A: 

You might want to look into the ASP.NET System.Web.Routing namespace, which was added in .NET 3.5 SP1 I believe:

http://blogs.msdn.com/mikeormond/archive/2008/05/14/using-asp-net-routing-independent-of-mvc.aspx

http://msdn.microsoft.com/en-us/library/system.web.routing.aspx

stusmith