I have inherited from a very small ASP.NET WebForms project, and my customer would like to add a second language to it.
For every “somepage.aspx”, I’d like to support a “second language path” version of it, like “fr/somepage.aspx”. I’d like to handle this using normal globalization (CurrentCulture + resource files in both languages) and avoid having to duplicate each page. I must keep the original paths valid, thus I have excluded ASP.NET MVC for now (for lack of knowing if I could continue to support “.aspx” paths).
Is this possible?
URL Routing is avalaible in for ASP.NET.
You could create two routes, the first being the route that catches your language:
{language}/{page}
The second route would be just
{page}
In MVC we can create route constraints that would enforce the Language to be of a specific value (so like en, en-us, etc) I’m not positive if the same can be done in regular ASP.NET WebForms routing.
Here are two articles that describe the topic of routing in WebForms (non-MVC)
http://msdn.microsoft.com/en-us/magazine/dd347546.aspx
and
http://weblogs.asp.net/scottgu/archive/2009/10/13/url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.aspx
EDITED TO ADD CODE SAMPLE
In my Global.asax I registered the following:
I also created a seperate Class (see asp.net 4.0 web forms routing – default/wildcard route as a guide.)
This works because when no locale is specified in the URL the default view engine for Web Forms takes over. It also works when a 2 letter locale (en? us? etc) is used. In MVC we can use an IRouteConstraint and do all kinds of checking, like making sure the locale is in a list, checking to see if the path exists, etc but in WebForms the only option for a constraint is using a RouteValueDictonary.
Now, I know there is an issue with the code as-is, default documents don’t load. So http://localhost:25436/en/ does not load the default document of default.aspx, but http://localhost:25436/en/default.aspx does work. I’ll leave that to you to resolve.
I tested this with sub directories and it works.