As I am constructing a blog section in my website I would like to know how to render each of the blog post in unique page template or say view. I do not want to create aspx manually and then naming them with headings SEO.
Step 1 : I have created a table where it can totally store all the details, including image, content, heading and I am able to retrieve these values to bind it further in the repeater. Working fine
Step 2: However, Now next thing is,there is blog details page which will be displayed when clicked on any of the blogs, but will it bear the different URL as to match with the heading ?
Assume currently URL is www.xyz.com/blog/blogdeatils.aspx and if it is rendering a article which talks about wikipedia then I want my URL to be www.xyz.com/blog/how-wikipedia-works (no aspx extension)
Is this possible ? Thank you all
2
Answers
This has been called as “routing”. Add Global.asax to your project and next is just an example of your file:
And in your BlogDetails.aspx you may use next code to fetch the title of the article:
And then use this for retrieving information from a database.
Your Global.ascx file’s content:
Consume that you have some table Articles, which contains such columns as ID, Name, Image, Info. And you have Image control for an image and Label control for a detail information in your BindDetails.aspx. So your BindDetails.aspx.cs will be (excepting namespaces):
And let’s think, that you have two articles with names “How-to-clean-home” and “How-to-clean-a-car“. Now you may give everybody links like xyz.com/blog/How-to-clean-home and xyz.com/blog/How-to-clean-a-car and it will work.
Hope it helps.