I have a simple web form application. I have one page called "show.aspx" which is responsible for displaying my article by an article Id.
At first I used to use QueryString to fetch article Id and on the basis of that Id I displayed article. However I knew that the url was not SEO friendly.
My URL was like this: mysite.com/article/show.aspx?articleid=7737
So I decided to move to URL rewriting, but since I had no experience in that I ended up with using URL routing technique.
So currently my url is like this: mysite.com/article/7737/ It works fine. I get the value of article with {articleid} parameter, defined in my global.asax file.
But I want to get my url something like this: mysite.com/article/article-title-from-database/
is it possible to fetch the title from database and re write url with applying hyphen between each word?
even I am ok if I need to pass two parameters like this: article/{articleid}/{title}/
Following is my Global.asax
<%@ Application Language="C#" %>
<%@ Import Namespace="System.Web.Routing" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("ArticleDetails","article/{articleId}", "~/article/show.aspx");
}
</script>
And My show.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (RouteData.Values["articleId"].ToString() != string.Empty)
{
Articles.rptArticle = rptDisplayArticle;
Articles.rptHashTags = rptHashTags;
Comments.rptComments = rptDisplayComments;
Articles.articleId = RouteData.Values["articleId"] as string;
Articles.Show();
if (!Comments.show())
{
lblNoComments.Text = "NO COMMENTS";
}
if (Authorization.Authorize())
{
panCommentPost.Visible = true;
ltLoginPrompt.Text = "POST A COMMENT";
}
}
else
{ Server.Transfer("~/404.html"); }