You need to ensure that the routes are registered correctly

You are developing an ASP.NET MVC 2 Web application that displays product details. The
global.asax.cs file contains the following code segment
01 public static void registerRoutes(RouteCollection routes)
02 {
03 routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);
04 routes.MapRoute(“Default”, “{controller}/{action}/{id}”, new {controller = “Home”, action =
“index”, id =
UrlParameter.Optional});
05 }
The URL “/products/PRODUCTNAME”, where PRODUCTNAME is the name of the product, must give
details for the product that is stored in a Microsoft SQL Server database. You need to ensure that the
routes are registered correctly. What should you do?

You are developing an ASP.NET MVC 2 Web application that displays product details. The
global.asax.cs file contains the following code segment
01 public static void registerRoutes(RouteCollection routes)
02 {
03 routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);
04 routes.MapRoute(“Default”, “{controller}/{action}/{id}”, new {controller = “Home”, action =
“index”, id =
UrlParameter.Optional});
05 }
The URL “/products/PRODUCTNAME”, where PRODUCTNAME is the name of the product, must give
details for the product that is stored in a Microsoft SQL Server database. You need to ensure that the
routes are registered correctly. What should you do?

A.
Replace line 04 with the following code segment
routes.MapRoute(“products/{productName}, “ProductDetails”, new {controller = “Products”, action
= “index”,
productName = UrlParameter.Optional});

B.
Add the following code segment between lines 04 and 05
routes.MapRoute(“ProductDetails, “products/{productName}”, new {controller = “Products”,
actions=”index”,
productName = UrlParameter.Optional});

C.
Replace lines 03 and 04 with the following code segment
routes.MapRoute(“products/{productName}”, “ProductDetails”, new {controller =”Products”,
action=”Index”,
productName=UrlParameter.Optional});

D.
Add the following code segment between lines 03 and 04.
routes.MapRoute(“ProductDetails”,”products/{productName}”, new {controller=”products”, action
=”Index”,
productName = UrlParameter.Optional});

Explanation:
ASP.NET MVC checks incoming URL requests against routes in the order they were registered, so you
need to add them in the order of most to least specific.
http://richarddingwall.name/2008/08/09/three-common-aspnet-mvc-url-routing-issues/



Leave a Reply 0

Your email address will not be published. Required fields are marked *