maryam it

maryam it

  • NA
  • 14
  • 787

How do I pass parameters to another page using ASP.NET friendly URL?

Apr 14 2021 6:59 AM
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:
  1. protected void doc_link_Click1(object sender, EventArgs e)  
  2. {  
  3. Response.RedirectToRoute("ArticlesDetails"new { articleName= "TheName" });  
  4. }  
  5. ArticleDetail.asp:  
  6. protected void Page_Load(object sender, EventArgs e)  
  7. {  
  8.       if (!Page.IsPostBack)  
  9.       {  
  10.            var name = Page.RouteData.Values["articleName"];  
  11.            if (name!=null)  
  12.               {  
  13.                 switch (name.ToString())  
  14.                 {  
  15.                  case ("TheName"):  
  16.                  {  
  17.                    //dosomething  
  18.                     break;  
  19.                  }  
  20.                 default:  
  21.                     break;  
  22.                 }  
  23.             }  
  24.       }  
  25. }  
global.asax:
  1. void Application_Start(object sender, EventArgs e)  
  2. {  
  3.   RouteConfig.RegisterRoutes(RouteTable.Routes);  
  4. }  
RouteConfig.cs:
  1. public static class RouteConfig  
  2. {  
  3.    public static void RegisterRoutes(RouteCollection routes)  
  4.    {  
  5.      var settings = new FriendlyUrlSettings();  
  6.      settings.AutoRedirectMode = RedirectMode.Permanent;  
  7.      routes.EnableFriendlyUrls(settings);  
  8.      RouteTable.Routes.MapPageRoute("Articles""Articles""~/Articles.aspx");  
  9.      RouteTable.Routes.MapPageRoute("ArticlesDetails""ArticlesDetails/{articleName}""~/ArticlesDetails.aspx");  
  10.     }  
  11. }

Answers (2)