Prafulla Sahu

Prafulla Sahu

  • NA
  • 213
  • 22.1k

Attribute based routing is not working

Jan 3 2018 9:31 AM
Hi I have created a small demo application to test Attribute based routing but no luck till now. Need some suggestions.
 
Route.config class  
 
  1. public class RouteConfig  
  2.     {  
  3.         public static void RegisterRoutes(RouteCollection routes)  
  4.         {  
  5.             routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  
  6.   
  7.             routes.MapMvcAttributeRoutes();  
  8.   
  9.             routes.MapRoute(  
  10.                 name: "Default",  
  11.                 url: "{controller}/{action}/{id}",  
  12.                 defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }  
  13.             );  
  14.         }  
  15.     }  
TestingController
    1. public class TestingController : Controller  
    2.    {  
    3.        // GET: Testing  
    4.   
    5.        [Route("demo")]  
    6.        public ActionResult Index()  
    7.        {  
    8.            return View();  
    9.        }  
    10.   
    11.        public ActionResult products()  
    12.        {  
    13.            return Content("All products");  
    14.        }  
    15.    }  
 This is a simple demo program only but banging my head to figure out why it is not working.
 
For your reference I am using visual studio 2015.
 
http://localhost:1352/Testing/products: This one is working 
http://localhost:1352/Testing/demo : This one is not working
 
 Please suggest something.

Answers (2)