I installed the Microsoft.Asp.Net.FriendlyUrls.Core.dll via NuGet to an existing asp.net 4.5 webforms website.
I have the following in the RouteConfig file
public static void RegisterRoutes(RouteCollection routes)
{
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
routes.MapPageRoute("frUrl", "frurltest/{id}", "~/frurltest.aspx");
}
**Global.asax**
void Application_Start(object sender, EventArgs e)
{
RouteConfig.RegisterRoutes(System.Web.Routing.RouteTable.Routes);
}
In the frurltest.aspx I try to get the "id" from the RouteData like below:
string id = String.Empty;
if (RouteData.Values["id"] != null)
{
id = RouteData.Values["id"].ToString();
}
Response.Write("id= " + id);
With the following url: http://localhost:48484/frurltest/2
I don't get the value for the "id". RouteData.Values.Count=0.
Any idea what am I missing here?
Note: Other than getting the routedata, the friendly url functionality is working i.e. say I navigate to /frutltest.aspx, it is changed to /frutlest and I can generate the links using $RouteUrl.
Update: After trial and errors I noticed if I move the EnableFriendlyUrls after MapPageRoute, it works. i.e.
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("frUrl", "frurltest/{id}", "~/frurltest.aspx");
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings);
}
All the examples I have see, uses as my initial non-working code. No idea why it works for them and not for me. Here's one similar question: RouteData.Values stays Empty