by Scott
21. April 2010 13:15
As I described before, I love the new routing feature in ASP.NET 4.0. I succesfully converted my code from Intelligencia over to the built in routing. The site ran great locally, but when I deployed to IIS7, I got 404's on every page that didn't have an extension. Those pages were my routed product pages.
Some googling led to to add a line to my web.config file. Here is is:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
This apparently forces IIS to invoke the routing module. I found no mention of this anywhere and was under the assumption I didn't have to modify any config files. Hope this helps somebody.
Here are some sources where I found this:
http://forums.asp.net/t/1523639.aspx
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
52e4f60c-f6d9-4495-a209-68c734b5bc4c|2|4.5
Tags:
SEO
by Scott
21. April 2010 13:07
I was reading ScottGu's blog the other day and decided to give the new URL routing in ASP.NET 4.0 a try. Got it to work great, just register the routes in global.asax and then pull out the data on the page where you need it.
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
RegisterRoutes(RouteTable.Routes);
}
void RegisterRoutes(RouteCollection routes)
{
routes.MapPageRoute("product-browse", "product/{name}_{id}", "~/Product.aspx");
routes.MapPageRoute("category-browse", "category/{name}_{id}", "~/CategoryPage.aspx");
routes.MapPageRoute("brand-browse", "brand/{name}_{id}", "~/BrandPage.aspx");
routes.MapPageRoute("search", "search/{*searchTerms}", "~/Search.aspx");
}
Above, I registered a route called product-browse where a page like http://mysite.com/product/some-great-toy_12 will get mapped to my Product.aspx page. Inside Product.aspx, you would just need to retrive your id (and the name if you need it)
string name = Page.RouteData.Values["name"] as string;
int productId = Convert.ToInt32(Page.RouteData.Values["id"]);
Now, I have the productId, pulled right off the URL without using querystrings like I've used in the past.
I like it!
7e9657d1-dc8e-4cb4-bf3a-dafec4e162fb|0|.0
Tags:
SEO