Skip to main content
Fixing formatting to show closing XML tag that was missing from output
Source Link
Dan Sinclair
  • 5.5k
  • 2
  • 20
  • 44

Controller:

public class ExampleController : Controller
{
    private readonly ISitecoreContext _sitecoreContext;

    public ExampleController ()
    {
        
    }     

    [System.Web.Http.HttpGet]
    // GET: Manifest
    public JsonResult Test()
    {
        return Json("test");         
    }
}

Register Route Pipeline:

public class RegisterTestApiRoute
{
    public virtual void Process(PipelineArgs args)
    {
        RouteTable.Routes.MapHttpRoute(
            "testApi",
            "api/testing/{controller}/{action}"
        );
    }
}

Patching route in config:

<pipelines>
  <initialize>
    <processor type="TestProject.Pipelines.RegisterTestApiRoute, TestProject" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" />
    
  </initialize>
</pipelines>
  

With all above in place the following default Sitecore webapi route works fine:

http://localsitecore/api/sitecore/example/test

but my custom route

http://localsitecore/api/testing/example/test

returns below error:

{"Message":"No HTTP resource was found that matches the request URI 'http://localsitecore/api/testing/example/test'.","MessageDetail":"No type was found that matches the controller named 'example'."}

I'm not sure why controller is not found, in a properly compiled code, I've tried below:

  • Restarted IIS
  • killed worker processes
  • cleared Visual Studio temp files

No luck..

even browsed my project dll with reflector, the controller exists..

Am I missing anything here...?

Controller:

public class ExampleController : Controller
{
    private readonly ISitecoreContext _sitecoreContext;

    public ExampleController ()
    {
        
    }     

    [System.Web.Http.HttpGet]
    // GET: Manifest
    public JsonResult Test()
    {
        return Json("test");         
    }
}

Register Route Pipeline:

public class RegisterTestApiRoute
{
    public virtual void Process(PipelineArgs args)
    {
        RouteTable.Routes.MapHttpRoute(
            "testApi",
            "api/testing/{controller}/{action}"
        );
    }
}

Patching route in config:

<pipelines>
  <initialize>
    <processor type="TestProject.Pipelines.RegisterTestApiRoute, TestProject" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" />
    
  </initialize>
 

With all above in place the following default Sitecore webapi route works fine:

http://localsitecore/api/sitecore/example/test

but my custom route

http://localsitecore/api/testing/example/test

returns below error:

{"Message":"No HTTP resource was found that matches the request URI 'http://localsitecore/api/testing/example/test'.","MessageDetail":"No type was found that matches the controller named 'example'."}

I'm not sure why controller is not found, in a properly compiled code, I've tried below:

  • Restarted IIS
  • killed worker processes
  • cleared Visual Studio temp files

No luck..

even browsed my project dll with reflector, the controller exists..

Am I missing anything here...?

Controller:

public class ExampleController : Controller
{
    private readonly ISitecoreContext _sitecoreContext;

    public ExampleController ()
    {
        
    }     

    [System.Web.Http.HttpGet]
    // GET: Manifest
    public JsonResult Test()
    {
        return Json("test");         
    }
}

Register Route Pipeline:

public class RegisterTestApiRoute
{
    public virtual void Process(PipelineArgs args)
    {
        RouteTable.Routes.MapHttpRoute(
            "testApi",
            "api/testing/{controller}/{action}"
        );
    }
}

Patching route in config:

<pipelines>
  <initialize>
    <processor type="TestProject.Pipelines.RegisterTestApiRoute, TestProject" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" />
  </initialize>
</pipelines>
 

With all above in place the following default Sitecore webapi route works fine:

http://localsitecore/api/sitecore/example/test

but my custom route

http://localsitecore/api/testing/example/test

returns below error:

{"Message":"No HTTP resource was found that matches the request URI 'http://localsitecore/api/testing/example/test'.","MessageDetail":"No type was found that matches the controller named 'example'."}

I'm not sure why controller is not found, in a properly compiled code, I've tried below:

  • Restarted IIS
  • killed worker processes
  • cleared Visual Studio temp files

No luck..

even browsed my project dll with reflector, the controller exists..

Am I missing anything here...?

Small formatting and spelling improvements
Source Link
Peter Procházka
  • 9.5k
  • 2
  • 30
  • 71

Controller:

public class ExampleController : Controller
{
    private readonly ISitecoreContext _sitecoreContext;

    public ExampleController ()
    {
        
    }     

    [System.Web.Http.HttpGet]
    // GET: Manifest
    public JsonResult Test()
    {
        return Json("test");         
    }
}

Register Route Pipeline:

public class RegisterTestApiRoute
{
    public virtual void Process(PipelineArgs args)
    {
        RouteTable.Routes.MapHttpRoute(
            "testApi",
            "api/testing/{controller}/{action}"
        );
    }
}

patchingPatching route in config:

<pipelines>
  <initialize>
    <processor type="TestProject.Pipelines.RegisterTestApiRoute, TestProject" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" />
    
  </initialize>

withWith all above in place the following default sitecoreSitecore webapi route works fine:

http://localsitecore/api/sitecore/example/test

but my custom route

http://localsitecore/api/testing/example/test

returns below error:

{"Message":"No HTTP resource was found that matches the request URI 'http://localsitecore/api/testing/example/test'.","MessageDetail":"No type was found that matches the controller named 'example'."}

{"Message":"No HTTP resource was found that matches the request URI 'http://localsitecore/api/testing/example/test'.","MessageDetail":"No type was found that matches the controller named 'example'."}

I'm not sure why controller is not found, in a properly compiled code, I've tried below:

  • Restarted IIS
  • killed worker processes
  • cleared Visual Studio temp files

No luck..

even browsed my project dll with reflector, the controller exists..

Am I missing anything here...?

Controller

public class ExampleController : Controller
{
    private readonly ISitecoreContext _sitecoreContext;

    public ExampleController ()
    {
        
    }     

    [System.Web.Http.HttpGet]
    // GET: Manifest
    public JsonResult Test()
    {
        return Json("test");         
    }
}

Register Route Pipeline

public class RegisterTestApiRoute
{
    public virtual void Process(PipelineArgs args)
    {
        RouteTable.Routes.MapHttpRoute(
            "testApi",
            "api/testing/{controller}/{action}"
        );
    }
}

patching route in config

<pipelines>
  <initialize>
    <processor type="TestProject.Pipelines.RegisterTestApiRoute, TestProject" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" />
    
  </initialize>

with all above in place the following default sitecore webapi route works fine:

http://localsitecore/api/sitecore/example/test

but my custom route

http://localsitecore/api/testing/example/test

returns below error:

{"Message":"No HTTP resource was found that matches the request URI 'http://localsitecore/api/testing/example/test'.","MessageDetail":"No type was found that matches the controller named 'example'."}

I'm not sure why controller is not found, in a properly compiled code, I've tried below:

  • Restarted IIS
  • killed worker processes
  • cleared Visual Studio temp files

No luck..

even browsed my project dll with reflector, the controller exists..

Am I missing anything here...?

Controller:

public class ExampleController : Controller
{
    private readonly ISitecoreContext _sitecoreContext;

    public ExampleController ()
    {
        
    }     

    [System.Web.Http.HttpGet]
    // GET: Manifest
    public JsonResult Test()
    {
        return Json("test");         
    }
}

Register Route Pipeline:

public class RegisterTestApiRoute
{
    public virtual void Process(PipelineArgs args)
    {
        RouteTable.Routes.MapHttpRoute(
            "testApi",
            "api/testing/{controller}/{action}"
        );
    }
}

Patching route in config:

<pipelines>
  <initialize>
    <processor type="TestProject.Pipelines.RegisterTestApiRoute, TestProject" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" />
    
  </initialize>

With all above in place the following default Sitecore webapi route works fine:

http://localsitecore/api/sitecore/example/test

but my custom route

http://localsitecore/api/testing/example/test

returns below error:

{"Message":"No HTTP resource was found that matches the request URI 'http://localsitecore/api/testing/example/test'.","MessageDetail":"No type was found that matches the controller named 'example'."}

I'm not sure why controller is not found, in a properly compiled code, I've tried below:

  • Restarted IIS
  • killed worker processes
  • cleared Visual Studio temp files

No luck..

even browsed my project dll with reflector, the controller exists..

Am I missing anything here...?

Source Link
nari447
  • 447
  • 7
  • 19

Sitecore WebApi custom route not working controller not found

Controller

public class ExampleController : Controller
{
    private readonly ISitecoreContext _sitecoreContext;

    public ExampleController ()
    {
        
    }     

    [System.Web.Http.HttpGet]
    // GET: Manifest
    public JsonResult Test()
    {
        return Json("test");         
    }
}

Register Route Pipeline

public class RegisterTestApiRoute
{
    public virtual void Process(PipelineArgs args)
    {
        RouteTable.Routes.MapHttpRoute(
            "testApi",
            "api/testing/{controller}/{action}"
        );
    }
}

patching route in config

<pipelines>
  <initialize>
    <processor type="TestProject.Pipelines.RegisterTestApiRoute, TestProject" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeRoutes, Sitecore.Mvc']" />
    
  </initialize>

with all above in place the following default sitecore webapi route works fine:

http://localsitecore/api/sitecore/example/test

but my custom route

http://localsitecore/api/testing/example/test

returns below error:

{"Message":"No HTTP resource was found that matches the request URI 'http://localsitecore/api/testing/example/test'.","MessageDetail":"No type was found that matches the controller named 'example'."}

I'm not sure why controller is not found, in a properly compiled code, I've tried below:

  • Restarted IIS
  • killed worker processes
  • cleared Visual Studio temp files

No luck..

even browsed my project dll with reflector, the controller exists..

Am I missing anything here...?