November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
My thought is this should be a Web API configuration, instead of Commerce.
What's your Global.asax.cs looks like, at least the Application_Start
method?
/Q
The Global.asax.cs is triggering GlobalConfiguration.Configure(WebApiConfig.Register); in it's Application_Start
protected void Application_Start() { // Register Display Options var options = ServiceLocator.Current.GetInstance<DisplayOptions>(); options .Add("full", "/displayoptions/full", ContentAreaTags.FullWidth, "", "epi-icon__layout--full") .Add("wide", "/displayoptions/wide", ContentAreaTags.TwoThirdsWidth, "", "epi-icon__layout--two-thirds") .Add("narrow", "/displayoptions/narrow", ContentAreaTags.OneThirdWidth, "", "epi-icon__layout--one-third"); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); }
And the line causing the error is the config.MapHttpAttributeRoutes(); in WebApiConfig:
using System.Web.Http; namespace WebApplication { public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web API routes config.MapHttpAttributeRoutes(); // Other Web API configuration not shown. } } }
This is just a class I created following the articles above but since we use the integration it seems like this simple way doesn't work. Tried to change the RoutePrefix to "api/commerce" just in case the "commerceapi" I set wasn't causing the issue but still same result
Seem I'm getting a littel bit closer to the solution by doing the following changes:
In the WebApiConfig I removed the config.MapHttpAttributeRoutes() and instead added a registration of the route I want to use:
public static void Register(HttpConfiguration config) { // Web API routes //config.MapHttpAttributeRoutes(); // Other Web API configuration not shown. config.Routes.MapHttpRoute( name: "CommerceApi", routeTemplate: "api/{controller}/{action}"); }
Changing the Controller to this:
[RoutePrefix("api/commerce")] public class CommerceApiController : ApiController { [Route("status")] [HttpGet] public IHttpActionResult Status() { return Ok(); } }
Now I don't get the standard 404, instead I'm presented with the following XML result:
<Error> <Message>No HTTP resource was found that matches the request URI 'http://localhost/api/commerce/status/'. </Message> <MessageDetail>No type was found that matches the controller named 'commerce'. </MessageDetail> </Error>
Have tried some different route settings but I can't get it to function correctly
Efter some more researching I'm back to square one. This since the custom routes specified in WebApiConfig is not for Attribute routing and this way of specifying routes will not find controllers specified by routes or based on the APiController.
So now I'm stuck with not being able to call the
config.MapHttpAttributeRoutes();
without causing the 'MS_attributerouteWebApi' error.
Nudging this - I too am having great difficulty getting WebAPI to work in an EPiServer, Commerce & EPiFind project.
Did you get anywhere?
The following article allowed me to see the routes in the RouteTable and I never see any of my attributed ones!
My gut is telling me something in Commerce or Find is doing something to register routes before my code runs.
No after we spent some time trying to get this to work we dropped it and handled the Actions on specific PageControllers. It was a while ago and haven't looked at it again I'm afraid.
Thanks for letting me know Tobais,
Im not too far off that point myself but both the Quicksilver reference implementation from EPiServer and the Commerce Starter Kit from Oxxas have a WebAPI integration (one with route attribution and one without). So I hopeful it can work!.
I've bben hacking around so long I cant tell whats going on - but right now neither approach is working.
I even tried on a new, blank EPiServer project (no add-ons, latest version - 9.x) and the route attribution worked flawlessy :(
There is something not right in my project!
Hi
Trying to get our own Web Api 2 controllers to work within a solution with EPiServer Commerce and the EPiserver Web Api 2 based integration. the Integration which has the route of episerverapi/ works since it's used in an Perfion integration but how do I get my own api to work?
Following these articles:
http://world.episerver.com/Blogs/Linus-Ekstrom/Dates/2014/7/Built-in-auto-suggestion-editor/
http://www.dcaric.com/blog/episerver-login-functionality-using-web-api-2
I have a basic Controller setup and when I try to register attributerouting in Global.asax.cs like this:
I get the following error
But if I leave out the registration from Global.asax.cs my routes does not work. Made a simple test controller method like this:
But all I get is a 404 when calling http://localhost/commerceapi/status. Is it some registration I'm missing and how does this work when the EPiServer.Integration is installed?