Monday, May 5, 2008

A Look at ASP.NET 2.0's URL Mapping

4GuysFromRolla.com: "A Look at ASP.NET 2.0's URL Mapping"


We can use ASP.NET 2.0's URL mapping feature to provide a friendly URL, like ~/Beverages.aspx. The following element markup provides eight mappings, creating a friendly URL for each of the categories in the Northwind database's Categories table. With these mappings in place, a user can view the products in the Beverages category by visiting either ~/ProductsByCategory.aspx?CategoryID=1&CategoryName=Beverages or ~/Beverages.aspx.


...

...


url="~/Beverages.aspx"
mappedUrl="~/ProductsByCategory.aspx?CategoryID=1&CategoryName=Beverages" />
url="~/Condiments.aspx"
mappedUrl="~/ProductsByCategory.aspx?CategoryID=2&CategoryName=Condiments" />
url="~/Confections.aspx"
mappedUrl="~/ProductsByCategory.aspx?CategoryID=3&CategoryName=Confections" />
url="~/Dairy.aspx"
mappedUrl="~/ProductsByCategory.aspx?CategoryID=4&CategoryName=Dairy+Products" />
url="~/Grains.aspx"
mappedUrl="~/ProductsByCategory.aspx?CategoryID=5&CategoryName=Grains+and+Cereals" />
url="~/Meat.aspx"
mappedUrl="~/ProductsByCategory.aspx?CategoryID=6&CategoryName=Meat+and+Poultry" />
url="~/Produce.aspx"
mappedUrl="~/ProductsByCategory.aspx?CategoryID=7&CategoryName=Produce" />
url="~/Seafood.aspx"
mappedUrl="~/ProductsByCategory.aspx?CategoryID=8&CategoryName=Seafood" />


No comments: