Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using URLRewriter it is working fine, As you can see in web config file 'ViewPost.aspx' is being used to rewrite url to display article. Now i need one more page 'ViewPost2.aspx' for the same. how it is possible?

http://urlrewriter.net/[^]

in web web-config file
XML
<rewriter>

  <rewrite url="(.+)-(.+).aspx" to="~/ViewPost.aspx?id=$2"/>

  </rewriter>


Generating URL.
XML
<asp:HyperLink ID="hlTitle" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"sub")%>'
 NavigateUrl='<%#GenerateURL(DataBinder.Eval(Container.DataItem,"sub"),DataBinder.Eval(Container.DataItem,"Id"))%>'></asp:HyperLink>


in code behind.
C#
public static string GenerateURL(object Title, object strId)
   {
       string strTitle = Title.ToString();

       #region Generate SEO Friendly URL based on Title
       //Trim Start and End Spaces.
       strTitle = strTitle.Trim();

       //Trim "-" Hyphen
       strTitle = strTitle.Trim('-');

       strTitle = strTitle.ToLower();
       char[] chars = @"$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray();
       strTitle = strTitle.Replace("c#", "C-Sharp");
       strTitle = strTitle.Replace("vb.net", "VB-Net");
       strTitle = strTitle.Replace("asp.net", "Asp-Net");

       //Replace . with - hyphen
       strTitle = strTitle.Replace(".", "-");

       //Replace Special-Characters
       for (int i = 0; i < chars.Length; i++)
       {
           string strChar = chars.GetValue(i).ToString();
           if (strTitle.Contains(strChar))
           {
               strTitle = strTitle.Replace(strChar, string.Empty);
           }
       }

       //Replace all spaces with one "-" hyphen
       strTitle = strTitle.Replace(" ", "-");

       //Replace multiple "-" hyphen with single "-" hyphen.
       strTitle = strTitle.Replace("--", "-");
       strTitle = strTitle.Replace("---", "-");
       strTitle = strTitle.Replace("----", "-");
       strTitle = strTitle.Replace("-----", "-");
       strTitle = strTitle.Replace("----", "-");
       strTitle = strTitle.Replace("---", "-");
       strTitle = strTitle.Replace("--", "-");

       //Run the code again...
       //Trim Start and End Spaces.
       strTitle = strTitle.Trim();

       //Trim "-" Hyphen
       strTitle = strTitle.Trim('-');
       #endregion

       //Append ID at the end of SEO Friendly URL

       //strTitle = "~/Label/"  +  strTitle + "-" + strId + ".aspx";

      strTitle = strTitle + "-" + strId + ".aspx";

       return strTitle;
   }


Full Reference: code i took from here.
http://dotnetguts.blogspot.ae/2008/07/url-rewriting-with-urlrewriternet.html[^]
Posted
Updated 23-Jun-15 20:00pm
v2
Comments
deepankarbhatnagar 23-Jun-15 8:38am    
Not getting , please explain
aspdotnetkhan 24-Jun-15 2:04am    
i want to use multiple pages to rewrite url.
Example: 'ViewPost.aspx' i am using to rewrite url to display article and now i need one more page "ViewPost2.aspx" for the same purpose.
aspdotnetkhan 24-Jun-15 2:28am    
dear abhishek,

I want to follow the same code from 'http://urlrewriter.net'.

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