I Need your Help Please; I'm developing a asp.net web application using c# I used Microsoft AspNet FriendlyUrls to make url without the suffix aspx in App_Code>App_start I added the following class
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
var settings = new FriendlyUrlSettings();
settings.AutoRedirectMode = RedirectMode.Permanent;
routes.EnableFriendlyUrls(settings,new WebMethodFriendlyUrlResolver());
}
public class WebMethodFriendlyUrlResolver : WebFormsFriendlyUrlResolver
{
public override string ConvertToFriendlyUrl(string path)
{
if (HttpContext.Current.Request.PathInfo != string.Empty)
{
return path;
}
else
{
return base.ConvertToFriendlyUrl(path);
}
}
}
}
in Global.asax i used the following code
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RouteConfig.RegisterRoutes(System.Web.Routing.RouteTable.Routes);
}
it's working fine for dropping aspx part from url NOW.......... I have a search page uses 3 parameters in url , as a example (Plumber,Cairo,Dar Elsalam)
.../search/find?Syx=job=Plumber%20+%20state=CAIRO%20+%20city=ELSALAM%20DAR%20+%20
How to make Up URL become
.../search/plumber-in-dar-elsalam
I Would be appreciated to Your ideas
i searched over internet for a solution but couldn't find a suitable solution to my case
I tried this code
routes.MapPageRoute("plum-darelsalam", "plumber-in-dar-elsalam", "~/find?Syx=job=Plumber%20+%20state=CAIRO%20+%20city=ELSALAM%20DAR%20+%20.aspx");
after
routes.EnableFriendlyUrls(settings,new WebMethodFriendlyUrlResolver());
But didn’t work ☹️
Well, with this URL
/search/findSyx=job=Plumber%20+%20state=CAIRO%20+%20city=ELSALAM%20DAR%20+%20
As a friendly URL, it would become:
(or at least close to above).
You can have:
or even
Note that in above, assuming the base page is "projects", then you can make some nice links quite much anyway you want. You could even have this:
However, it "most often" better to include what the "thing" is, so
Note that the "extra" values or key words you decide to have is 100% up to you.
NOW THE WHOPPER part!!!!
.net does not automatic CHANGE the old style URL's you have, nor will the NEW format work my some act of magic. YOU the developer NOW have to grab and use these new values.
So, code will look like this:
So, there is NOT a automatic conversion of "old style" parameter's to NEW style, you have to write the code to use and deal with the new style of URL parameter's. (this will require new code on your part).
So, in above, you can say use this:
or
And REALLY nice of course is users don't think of parameter's, but will not only see a nice clean link, but one that looks like a "folder", and they can ALSO share such links.
And while users can "mess" with parameter's, they are hard, but friendly URL's are so nice, they often will start to use them to get to a given quote, or even share such links.
So, as old style URL with parameter's, you might have this:
The above now becomes
Or maybe
So, you can make really nice URL's as a result, but YOU the developer WILL THEN have to get/grab/process/use/write code using the GetFriendlyUrlSegments, and there is not some automatic, or auto magic conversion that occurs for you.
You can certainly support both types of URL parameter's. That will mean you have to keep your existing old style code, and also THEN add additional new code for the new type of parameter's - they are not "one to one" or interchangeable.