locked
ApiController routing works locally, not when published to Azure RRS feed

  • Question

  • User-608380155 posted

    I am trying to upgrade a Mobile Service to the App Service as required by Microsoft. Routing is accomplished by applying the [RoutePrefix("api/contname")] attribute to the class derived from ApiController and the [Route("contaction/{inputone}/{inputtwo}")] attribute to the action to be taken, which has signature ContAction(String inputone, String inputtwo). In the WebApiConfig, MapHttpAttributeRoutes is called. This works perfectly on my local machine. (Although, it does not show the happy smiley face that the mobile service used to show with the "Try it out" button -- it does in fact route my api call correctly). Then I publish to Azure. In the log from Azure, I see this:

    Information Message='Contname', Operation=DefaultHttpControllerSelector.SelectController
    Information Message='myService.Controllers.ContnameController', Operation=DefaultHttpControllerActivator.Create
    Information Message='myService.Controllers.ContnameController', Operation=HttpControllerDescriptor.CreateController
    Information Message='Selected action 'ContAction(String inputone, String inputtwo)'', Operation=ApiControllerActionSelector.SelectAction
    Information Operation=ContnameController.Dispose
    Information Message='No CorsPolicyProvider selected', Operation=AttributeBasedPolicyProviderFactory.GetCorsPolicyProvider
    Information Message='Contname', Operation=DefaultHttpControllerSelector.SelectController
    Information Message='myService.Controllers.ContnameController', Operation=DefaultHttpControllerActivator.Create
    Information Message='myService.Controllers.ContnameController', Operation=HttpControllerDescriptor.CreateController
    Information Message='Will use same 'JsonMediaTypeFormatter' formatter', Operation=JsonMediaTypeFormatter.GetPerRequestFormatterInstance
    Information Message='Selected formatter='JsonMediaTypeFormatter', content-type='application/json; charset=utf-8'', Operation=DefaultContentNegotiator.Negotiate
    Warning Message='UserMessage='No HTTP resource was found that matches the request URI 'https://mydomainname.azurewebsites.net/api/contname/contaction/wordsinputone/wordsinputtwo'.', MessageDetail='No action was found on the controller 'Contname' that matches the request.'', Operation=ApiControllerActionSelector.SelectAction, Status=404 (NotFound), Exception=System.Web.Http.HttpResponseException: Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details.
    at System.Web.Http.Controllers.ApiControllerActionSelector.ActionSelectorCacheItem.SelectAction(HttpControllerContext controllerContext)
    at System.Web.Http.Controllers.ApiControllerActionSelector.SelectAction(HttpControllerContext controllerContext)
    at System.Web.Http.Tracing.Tracers.HttpActionSelectorTracer.<>c__DisplayClass2.<System.Web.Http.Controllers.IHttpActionSelector.SelectAction>b__0()
    at System.Web.Http.Tracing.ITraceWriterExtensions.TraceBeginEnd(ITraceWriter traceWriter, HttpRequestMessage request, String category, TraceLevel level, String operatorName, String operationName, Action`1 beginTrace, Action execute, Action`1 endTrace, Action`1 errorTrace)

    It looks like it recognizes which controller to create. Then it looks like it finds the action to take. But then it disposes the controller, creates it again and subsequently does not find the action. Why would this work locally just fine and fail on Azure?

    This all worked perfectly on the mobile service. I am attempting to "upgrade" (not "migrate") to the app services. I made the changes as written up in the "upgrade" article and it works locally.

    Solution or debugging ideas appreciated. I have it logging when it initializes the controller and that happens. I have remotely debugged, but it just never calls the action, so I'm not sure how to track it down. Anywhere that I should be putting a try/catch that you can think of? 

    UPDATE: The answer is in the question, but I will try to leave this here for others. Evidently, the App Services does not provide a CorsPolicyProvider or my app service is not configured properly to provide one. In either case, providing one programmatically fixed this issue.

    Thursday, June 16, 2016 8:49 PM

All replies

  • User1289604957 posted

    Hi,

    Have you did the clear of the cache in your Azure App Service?

    Best,

    Maher

    Thursday, August 25, 2016 10:24 PM
  • User1289604957 posted

    Which version of Web API are you using?

    Saturday, August 27, 2016 5:45 PM