2013年6月14日 星期五

不同area 存在相同名稱的 controller 造成無法呼叫action

錯誤訊息如下:
找到多個與名稱為 'Product' 的控制器相符的型別。如果服務此要求 ('{controller}/{action}/{id}') 的路由沒有指定命名空間以搜尋符合該要求的控制器,就會發生這個情況。在這種情況下,請呼叫可接受 'namespaces' 參數的 'MapRoute' 方法的多載來註冊此路由。

解法:
RouteConfig.RegisterRoutes 指定namespace
routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                new[] { "erpweb.Controllers" }
            );

沒有留言:

自訂權限驗證機制

// 使用 filter [Route("api/[controller]")] [ApiController] [Authorize] [TypeFilter(typeof(CustomAsyncAuthorizationFilter))] public c...