https://github.com/ogaudefroy/routelocalization.webforms
ASP.Net localized routing for WebForms routes
https://github.com/ogaudefroy/routelocalization.webforms
asp-net routing seo webforms webforms-routes
Last synced: 10 months ago
JSON representation
ASP.Net localized routing for WebForms routes
- Host: GitHub
- URL: https://github.com/ogaudefroy/routelocalization.webforms
- Owner: ogaudefroy
- License: mit
- Created: 2016-09-03T17:16:33.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-11-09T09:31:45.000Z (about 9 years ago)
- Last Synced: 2025-01-23T12:15:42.967Z (about 1 year ago)
- Topics: asp-net, routing, seo, webforms, webforms-routes
- Language: C#
- Size: 23.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RouteLocalization.WebForms
ASP.Net localized routing for WebForms routes
[](https://ci.appveyor.com/project/ogaudefroy/routelocalization-webforms) [](https://badge.fury.io/nu/RouteLocalization.WebForms)
## Declare a localized route
Just add a configured LocalizationRouteCollection in your route tables.
This component acts as a wrapper containing all localized routes (neutral included) and maps to a [PageRouteHandler](https://msdn.microsoft.com/en-us/library/system.web.routing.pageroutehandler(v=vs.110).aspx).
```C#
var routes = new LocalizationRouteCollection(
virtualPath: "~/pages/offer/details.aspx",
defaults: null,
constraints: new RouteValueDictionary() { { "id", @"\d+" } }, });
route.AddTranslation(LocalizationRouteCollection.NeutralRoute, "neutral/neutral-{title}_{id}");
route.AddTranslation("en-US", "job/job-{title}_{id}");
route.AddTranslation("fr-FR", "offre-de-emploi/offre-{title}_{id}");
RouteTable.Routes.Add("OfferDetails", route);
```
## Retrieving route culture
Route culture can be easily retrieved as the culture is added in route values dictionary
```C#
protected override void InitializeCulture() {
var routeCulture = this.RouteData.Values["culture"] as string;
if (routeCulture != null) {
this.Culture = new CultureInfo(routeCulture);
this.UICulture = new CultureInfo(routeCulture);
}
}
```
## Outbound routing
```C#
// Classical way
RouteTable.Routes.GetVirtualPath(null, "OfferDetails", new RouteValueDictionary() {{"title", "chef-de-projet"}, {"id", 12}}).VirtualPath
// With explicit culture
RouteTable.Routes.GetVirtualPath(null, "OfferDetails", new RouteValueDictionary() {{"title", "chef-de-projet"}, {"id", 12}, {"id", "fr-FR"}).VirtualPath
// Through RouteUrlExpressionBuilder
```
Inspired by [RouteLocalization](https://github.com/Dresel/RouteLocalization)