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:
void RegisterRoutes(RouteCollection routes)
{
routes.Ignore("{resource}.asxd/{*pathInfo}");
routes.Add(
new Route(
"{locale}/{*url}", //Route Path
null, //Default Route Values
new RouteValueDictionary{{"locale", "[a-z]{2}"}}, //constraint to say the locale must be 2 letters. You could also use something like "en-us|en-gn|ru" to specify a full list of languages
new Utility.Handlers.DefaultRouteHandeler() //Instance of a class to handle the routing
));
}
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RegisterRoutes(RouteTable.Routes);
}
I also created a seperate Class (see asp.net 4.0 web forms routing - default/wildcard route as a guide.)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Compilation;
using System.Web.Routing;
using System.Web.UI;
namespace SampleWeb.Utility.Handlers
{
public class DefaultRouteHandeler:IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
//Url mapping however you want here:
string routeURL = requestContext.RouteData.Values["url"] as string ;
string pageUrl = "~/" + (!String.IsNullOrEmpty(routeURL)? routeURL:"");
var page = BuildManager.CreateInstanceFromVirtualPath(pageUrl, typeof(Page))
as IHttpHandler;
if (page != null)
{
//Set the <form>'s postback url to the route
var webForm = page as Page;
if (webForm != null)
webForm.Load += delegate
{
webForm.Form.Action =
requestContext.HttpContext.Request.RawUrl;
};
}
return page;
}
}
}
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.