Question

I have a deployment time issue with WebAPI and would be grateful if someone can help.

Routes:

        public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services

        // Web API routes
        config.MapHttpAttributeRoutes();
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        config.Routes.MapHttpRoute(
            name: "DefaultApi2",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
        config.Routes.MapHttpRoute(
            name: "DefaultApi3",
            routeTemplate: "api/{controller}/{action}/{lines}/{swapAxis}",
            defaults: new
            {
                controller = "LVChart",
                action = "Get",
                lines = RouteParameter.Optional, 
                swapAxis = RouteParameter.Optional
            }
        );
    }

Action :

    // GET api/<controller>
    public IEnumerable<string> Get1()
    {
        return new string[] { "value1", "value2" };
    }
    // GET api/<controller>
    [ActionName("Get")]
    public string Get([FromUri] List<Line> lines, bool swapAxis)
    {
        _lineBuilder = new LVLineBuilder(swapAxis);
        string result = BuildLines(lines);
        return result;
    }

OK now here's the problem. Both Get1 and Get(..) works well in localhost. However as soon as deployed on server (Note: I am only deploying webpages/js/dll using publishing wizard) Get1 works fine but Get throws "500 Internal Server Error"

The url for Get1 is

.../api/LVChart/Get1/

While Get is

.../api/LVChart/Get/?lines[]=15&lines[]=11&lines[]=12&lines[]=3&lines[]=10&lines[]=7&swapAxis=false

I am really running out of options about how to solve this.

Thanks

Was it helpful?

Solution

For this to work ,I think your custom routes should come above dafault route. i.e DefaultApi2 and DefaultApi3 should come above DefaultApi1.

Also to be RESTfull you can also try avoiding extra default routes and use only default route 1 and do HttpGet to /api/LVChart, like this

.../api/LVChart?lines[]=15&lines[]=11&lines[]=12&lines[]=3&lines[]=10&lines[]=7&swapAxis=false
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top