I'm using asp.net4 on visual studio 2012 and I installed the asp Friendly Url package. in the Article page, I want to redirect to the ArticleDetail page when the user presses the "read more" button and the "articleName" parameter passed to the ArticleDetail page too.
the problem is when I click on the button, the page redirects to the ArticleDetail page and the friendly URL is good(/ArticlesDetails/ArticleName )but when I press on any other link on ArticleDetails page(for example my site menu)it doesn't go on that page(for example homepage) and retain on ArticleDetail and just the URL changed to a wrong URL like "/ArticlesDetails/homepage"
Article.aspx:
- protected void doc_link_Click1(object sender, EventArgs e)
- {
- Response.RedirectToRoute("ArticlesDetails", new { articleName= "TheName" });
- }
- ArticleDetail.asp:
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!Page.IsPostBack)
- {
- var name = Page.RouteData.Values["articleName"];
- if (name!=null)
- {
- switch (name.ToString())
- {
- case ("TheName"):
- {
-
- break;
- }
- default:
- break;
- }
- }
- }
- }
global.asax:
- void Application_Start(object sender, EventArgs e)
- {
- RouteConfig.RegisterRoutes(RouteTable.Routes);
- }
RouteConfig.cs:
- public static class RouteConfig
- {
- public static void RegisterRoutes(RouteCollection routes)
- {
- var settings = new FriendlyUrlSettings();
- settings.AutoRedirectMode = RedirectMode.Permanent;
- routes.EnableFriendlyUrls(settings);
- RouteTable.Routes.MapPageRoute("Articles", "Articles", "~/Articles.aspx");
- RouteTable.Routes.MapPageRoute("ArticlesDetails", "ArticlesDetails/{articleName}", "~/ArticlesDetails.aspx");
- }
- }