If
you are working in Sitecore Helix Framework and going to call action method
like http://myinstance/api/sitecore/accounts/RenderResetPassword,
you may get error like
Server
Error in '/' Application.
Multiple
types were found that match the controller named 'accounts'. This can happen if
the route that services this request ('api/sitecore/{controller}/{action}')
does not specify namespaces to search for a controller that matches the
request. If this is the case, register this route by calling an overload of the
'MapRoute' method that takes a 'namespaces' parameter.
The request for 'accounts' has found the following matching controllers:
Feature.Abc.Accounts.Controllers.AccountsController
Feature.Xyz.Accounts.Controllers.AccountsController
The request for 'accounts' has found the following matching controllers:
Feature.Abc.Accounts.Controllers.AccountsController
Feature.Xyz.Accounts.Controllers.AccountsController
It’s
because of duplicate controller name in Abc and Xyz project.
To
fix this, we have to register custom MVC routes in Sitecore. For this, I
created one custom processor file “RegisterCustomRoute.cs” to
initialize pipeline.
You
have to register your duplicate controller as
public class RegisterCustomRoute
{
public virtual void Process(PipelineArgs args)
{
RouteTable.Routes.MapRoute
("AbcAccount",
"abc/{controller}/{action}/{id}",
new { controller = "Accounts", id = UrlParameter.Optional },
new[] { "Feature.Abc.Accounts.Controllers" }
);
RouteTable.Routes.MapRoute
("XyzAccount",
"xyz/{controller}/{action}/{id}",
new { controller = "Accounts", id = UrlParameter.Optional },
new[] { "Feature.Xyz.Accounts.Controllers" }
);
}
}
Here
I have append “abc” and “xyz” to separate the URL for account and specified
their Namespace as last parameter in MapRoute() method. Now you can call new URL as
With
this you don’t need to put “api/sitecore” in URL now for
accounts controller.
I
registered this Processor entry in config patch file customweb.config
<pipelines>
<initialize>
<processor type="MyProject.Website.RegisterCustomRoute,
MyProject.Website" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes,
Sitecore.Mvc']" />
</initialize>
</pipelines>
If
you are facing the same error, make sure to add entry in “RegisterCustomRoute.cs”
as highlighted
above.
먹튀사이트 잡는 고릴라의 먹튀검증 통과 메이저토토사이트 안전놀이터 추천 훌륭한 먹튀검증을 통한 안전토토사이트를 추천합니다 고릴라만의 검증 시스템은 특별합니다 전세계적인 먹튀검증을 인전받은 최고의 메이저사이트 추천을 합니다 자세한 내용은 내 웹 사이트를 방문하십시오 먹튀검증.
ReplyDelete