2

I'm trying to integrate the Web API into DNN7 module.

Controller & Mapper:

namespace MyControllers
{
    public class ExampleController : DnnApiController
        {
            #region "Web Methods"
            [DnnAuthorize()]
            [HttpGet()]
            public HttpResponseMessage HelloWorld()
            {
                try
                {
                    string helloWorld = "Hello World!";
                    return Request.CreateResponse(HttpStatusCode.OK, helloWorld);
                }
                catch (System.Exception ex)
                {
                    //Log to DotNetNuke and reply with Error
                    Exceptions.LogException(ex);
                    return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
                }
            }


    public class RouteMapper : IServiceRouteMapper
        {
            public void RegisterRoutes(IMapRoute mapRouteManager)
            {
                mapRouteManager.MapHttpRoute("MyControllers", "default", "{controller}/{action}", new[] { "MyControllers" });
            }
        }
}

Then I'm trying to access the HelloWorld method from the url

https://localhost/DesktopModules/MyControllers/API/Example/HelloWorld

and getting the

HTTP Error 404.0 - Not Found

Any suggestions on what can be missing?

tatigo
  • 2,174
  • 1
  • 26
  • 32
  • Not sure this is it, but what if you try a module without a period in the name/folder? – Chris Hammond Oct 06 '13 at 02:11
  • Moved the same code to a separate class library project, the output dll goes to the main bin of the website, removed all periods everywhere. trying to access with url this way: http://localhost/DesktopModules/[LibraryFolderName]/API/[ControllerName]/[MethodName] – tatigo Oct 06 '13 at 14:54
  • I'm lost here, maybe something in webconfig? – tatigo Oct 06 '13 at 14:55
  • Can you troubleshoot this using Fiddler. That's usually how I work through an issue with WebAPI. It's not even finding it, so I wonder if its something with the port (80 vs 443)??? – L_7337 Oct 06 '13 at 23:04
  • found the problem, the DesktopModules folder was an Application in IIS, this is apparently a no no to web api. – tatigo Oct 07 '13 at 05:33

1 Answers1

1

Solved!!! Turned out that the DesktopModules folder was as Application in IIS, which blocked the WebApi. So, if you get the non descriptive

HTTP Error 404.0 - Not Found

check the IIS first.

tatigo
  • 2,174
  • 1
  • 26
  • 32
  • 3
    I really wish I could figure out how to stop VS from doing that with my DNN templates – Chris Hammond Oct 07 '13 at 12:02
  • I wasn't using your template this time. Started thinking in the direction of what might be blocking the http handlers, so removed all web.configs and added them back one by one and then got this bright idea regarding application in IIS. – tatigo Oct 07 '13 at 15:50
  • 1
    That's interesting, so it isn't just my templates, that's eases my mind a bit :D – Chris Hammond Oct 07 '13 at 16:05
  • Chris, have you tried changing your templates project settings to use instead. – Ryan Gunn Oct 07 '13 at 16:15
  • 1
    @DNNDev.co.za great code example you've got there - http://www.dnndev.co.za/Home/post=187 - Thanks :) – tatigo Oct 07 '13 at 21:51
  • @tatigo - HOW did you debug the problem? -http://stackoverflow.com/questions/21676207/upgraded-to-webapi2-and-dotnetnuke-7-2-1-and-all-services-returning-404-0 – Rodney Feb 10 '14 at 11:41
  • @Rodney - I set up break points in Fiddler, the request was sent fine but was stopped at the server side, means something to do with IIS – tatigo Feb 10 '14 at 16:36
  • This isn't the fix for me and I am getting the same error. :( GET works fine, but I keep getting a 404 on POST. – Will Strohl Apr 03 '15 at 22:18