I have a profile site and now i want to make it easy to remember the url.
I have links like
- www.page.com/faq
- www.page.com/news/1
- www.page.com/rules
- www.page.com/profile/[USERNAME]
Now, i want to change the url, www.page.com/profile/[USERNAME] to be, www.page.com/[USERNAME]. The profile is a own area in my project.
My ProfileAreaRegistration.cs
public override string AreaName => "Profile";
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Profile_media",
"Profile/{ProfileName}/Media/{id}",
new
{
area = "Profile",
controller = "Media",
action = "Index"
},
new[] { "MySite.Areas.Profile.Controllers" });
context.MapRoute(
"Profile_default",
"Profile/{ProfileName}/{controller}/{action}/{id}",
new
{
area = "Profile",
controller = "Home",
action = "Index",
id = UrlParameter.Optional
},
new[] { "MySite.Areas.Profile.Controllers" });
}
My RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"News", // Route name
"News/{id}", // URL with parameters
new {controller = "News", action = "Index", id = UrlParameter.Optional},
new[] {"MySite.Controllers.News"}
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new {controller = "Home", action = "Index", id = UrlParameter.Optional},
new[] {"MySite.Controllers"}
);
}
How can i get www.page.com/rules and www.page.com/[USERNAME] working? When i enter www.page.com/[USERNAME], the area Profile should be called.
faqorrulesas it's username? That can cause lot's of conflicts in your routes...