Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 in 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"

What I have tried:

Article.aspx:
C#
protected void doc_link_Click1(object sender, EventArgs e)
   {
       Response.RedirectToRoute("ArticlesDetails", new { articleName= "TheName" });
   }

ArticleDetail.asp:
C#
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"):
                        {
                            //dosomething
                            break;
                        }
                    default:
                        break;
                }
            }
        }
        }

global.asax:
C#
void Application_Start(object sender, EventArgs e)
  {
      RouteConfig.RegisterRoutes(RouteTable.Routes);
  }

RouteConfig.cs:
C#
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");
Posted
Updated 13-Apr-21 20:47pm
v6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900