//Append ID at the end of SEO Friendly URL
strTitle = "~/productPage/" + strTitle + "-" + strId + ".aspx";
return strTitle;
}
MyQuestion:
it works fine, the problem is, I have to define, in everypage aspx page, GenerateURL(productID,productname) to generate user frinedly url. is there any technique to create the urls of all application QueryStrings in only one place.
faisalnext
Member
122 Points
40 Posts
Generate Frinedly URL Links : Url Rewriting
Jan 17, 2011 05:38 AM|LINK
I am using , http://urlrewriter.net opensource for URL rewritting, & I have following way to generate the pages.
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%#GenerateURL(DataBinder.Eval(Container.DataItem,"productID"),DataBinder.Eval(Container.DataItem,"productName"))%>'
Text='<%#Eval("productName") %>'> </asp:HyperLink>
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 = "~/productPage/" + strTitle + "-" + strId + ".aspx";
return strTitle;
}
MyQuestion:
it works fine, the problem is, I have to define, in everypage aspx page, GenerateURL(productID,productname) to generate user frinedly url. is there any technique to create the urls of all application QueryStrings in only one place.
anand.csharp
Member
608 Points
144 Posts
Re: Generate Frinedly URL Links : Url Rewriting
Jun 16, 2012 08:12 AM|LINK
yes you can do the same by creating url rules either on iis or do write some logis on globle.ascx.
UrlRewriting csharpmagic.com
Anand Kumar
ASP.NET Forum, Artilces, Blogs | www.CsharpMagic.com
Kianna
Member
28 Points
15 Posts
Re: Generate Frinedly URL Links : Url Rewriting
Oct 04, 2012 11:13 AM|LINK
Yes you can genrate the Friendly URL, Google perfer to your site, SEO friendly URL easy and helpful for user...