DotNetKick.com is an open-source project. Please report any bugs and let us know your great suggestions. Currently running svn revision 620 (rss)

Kick Spy!, Kick Zeitgeist and Kick Widgets

19
kicks
published 3 months, 6 days ago, submitted by janko janko 3 months, 6 days ago

jankoatwarpspeed.com — So, you hate such URLs Or you'll hate it after you realize how easy it is to make it nicer. Besides all, URL rewriting will improve your rankings on search engines. Search engines like Google will easily index your "static" URLs, instead of dynamic URLs. There are several ways to accomplish URL Rewriting. I'll explain how to do this by using HttpModule and how to overcome the postback bug that is the outcome of URL rewriting. Suppose you have a content management system that stores entire pages in the database. So you can have a Home page, and Home page can have sections Products and Services, and each one of these can have their own child pages or sections, and so on. So we want dynamic URL like this: Default.aspx?SectionID=5&ItemID=22 to look like /catalogue/furniture/chairs/chair5.aspx or whatever the business logic requirement is. In the example in this article I will not use a database in order to keep it simple, but you imagine there is a database that keeps the URL for each page. I'll use hard-coded Dictionary that will keep some sample pages. Note: You can download the full code in the attachment. First, we'll make a data access object that will search the database for requested url and return its dynamic url. These are the methods in SampleDAO that will simulate the database and getting the url from there: public string GetRealPath(string requestedUrl) { string path = ""; Dictionary<string, string> paths = GetPathsFromDatabase(); if (paths.ContainsKey(requestedUrl)) paths.TryGetValue(requestedUrl, out path); return path; } private static Dictionary<string, string> GetPathsFromDatabase() { Dictionary<string, string> paths = new Dictionary<string, string>(); paths.Add("/URLRewrite/FirstSection/Default.aspx".ToLower(), "/URLRewrite/Default.aspx?SectionID=1"); paths.Add("/URLRewrite/SecondSection/Default.aspx".ToLower(), "/URLRewrite/Default.aspx?SectionID=2"); paths.Add("/URLRewrite/FirstSection/Page1.aspx".ToLower(), "/URLRewrite/Default.aspx?SectionID=1&Item=1"); paths.Add("/URLRewrite/FirstSection/Page2.aspx".ToLower(), "/URLRewrite/Default.aspx?SectionID=1&Item=2"); paths.Add("/URLRewrite/SecondSection/Page1.aspx".ToLower(), "/URLRewrite/Default.aspx?SectionID=2&Item=1"); paths.Add("/URLRewrite/SecondSection/SubSection/AnotherOne/Page5.aspx".ToLower(), "/URLRewrite/Default.aspx?SectionID=2&Item=5"); paths.Add("/URLRewrite/Default.aspx".ToLo

Add a comment 3 comments | category: | Views: 274 | Get KickIt image code
tags: , | tag it

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:

Comments:
gaaah, is there a way to change the description, I copied a half of my website =)
posted by janko janko 3 months, 6 days ago
There are much better solutions out there than his this. IIS 7 has their own rewriter. There is also a ton of them on codeplex, just search for url rewriter.
posted by zigamorph zigamorph 3 months, 6 days ago
I use http://www.urlrewriting.net for rewritings, works without any issues. I currently use it for replacing a old web-form site to asp.net mvc, where i need to keep the .aspx ending (temporarily).

Performance-wise its invisible.
posted by duckie duckie 3 months, 6 days ago



information Login or create an account to comment on this story
 

Sponsored Link: www.carlist.ie

Search:

Ads via The Lounge