I installed Microsoft.Asp.Net.FriendlyUrls.Core.dll via NuGet on my existing asp.net 4.5 website webforms.
I have the following 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 frurltest.aspx, I'm trying to get the "id" from RouteData, as shown 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 do not get the value for "id". RouteData.Values.Count = 0.
Any idea what I'm missing here?
Note. . Besides getting routedata, the friendly url function works, that is, I go to /frutltest.aspx, it is changed to / frutlest, and I can generate links using $ RouteUrl.
Update:
After trial and error, I noticed that if you move EnableFriendlyUrls after MapPageRoute, it will work. 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);
}
, , . , , . : RouteData.Values