Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Sonja 133 posts 621 karma points
    Oct 15, 2018 @ 12:32
    Sonja
    0

    Web Api plugin controller

    Hi,

    I have a plugin controller

    [PluginController("heading")]
        public class MyPluginController : UmbracoApiController
        {
            // GET: api/SBMSPlugin
            public IEnumerable<string> GetAll()
            {
                return new string[] { "heading1", "heading2" };
            }
    }
    

    and I have plugin In App_Plugins named Heading enter image description here

    How can I add my web api plugin controller to the plugin package? Do i need to create the controller in app_plugins/heading or I have to do it in Controllers? Where can I find some examples? Thanks

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Oct 15, 2018 @ 12:35
    Dave Woestenborghs
    0

    Hi Sonja,

    You would be able to call your api with the following url

    http://yourdomain/umbraco/heading/myplugin/getall
    

    You can read some more how the routing works : https://our.umbraco.com/documentation/Reference/Routing/WebApi/#plugin-based-controller

    Dave

  • Sonja 133 posts 621 karma points
    Oct 15, 2018 @ 12:41
    Sonja
    0

    Hi Dave,

    Yes I've already seen this but if I need to distribute the controller to a client together with the plugin how can I do that? Otherwise what will be the point of plugin based web api if not to be distributed? I don't intend to host it, the client should.

    Thanks

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Oct 15, 2018 @ 12:53
    Dave Woestenborghs
    0

    You will need to send them the dll with the compiled code of your controller.

    The path will be the same.

    Dave

  • John Bergman 483 posts 1132 karma points
    Oct 16, 2018 @ 01:18
    John Bergman
    0

    I've not tried this, but you might be able to get it to work in the App_Code folder...

  • Sonja 133 posts 621 karma points
    Oct 17, 2018 @ 10:02
    Sonja
    0

    I'm trying to do it. I have created separate project with 1 controller and build a dll. Then in my main project I have added this dll. I've rebuild the initial project. Now I'm trying to call the web api like:

    http://myinitialproject.local/umbraco/myplugin/thedllcontroller/functionname but I'm getting 404. Am I missing something?

  • David Armitage 510 posts 2081 karma points
    Dec 27, 2019 @ 07:20
    David Armitage
    0

    Hi Sonja,

    Do you ever figure this out? I think I am having the same problem.

    I am trying to create a plugin/package which makes the use of an API or PluginController. So my angular code will http post to my cs.net controller.

    I have managed to get this to work by adding the plugin controller in AppCode folder but if I try and move this to my plugin folder within AppPlugins then I get a 404.

    I am guessing we need to leave this in the AppCode folder and when we publish the package we do something extra? Or an I on the right track attempting to move this into the AppPlugins?

    Thanks in advanced.

    David

  • John Bergman 483 posts 1132 karma points
    Dec 27, 2019 @ 09:10
    John Bergman
    0

    There is a nuget package called routedebugger.

    You can install it and turn it on in the web.config - it will output a list of all of the routes - from that you might be able to determine what the url is.

    Otherwise, post your class definition and the attributes, if any you have added to the class and method you are trying to call and maybe we can see what the issue is from that.

  • David Armitage 510 posts 2081 karma points
    Dec 27, 2019 @ 09:18
    David Armitage
    0

    Hi John,

    Thanks for your reply.

    I think the question is if the PluginController should be but in the AppPlugins folder or not. As I mentioned I have got this working by putting the controller in the AppCode folder

    I think this is the correct setup rather than putting this file in the AppPlugins. I am just looking for confirmation if I am on the right track with this or if I am totally wrong the plugin controllers should in-fact be stored in the AppPlugins. At that point I would have to start figuring out why the route isn't working.

  • John Bergman 483 posts 1132 karma points
    Dec 27, 2019 @ 09:46
    John Bergman
    1

    In my case, I have my plugins in a separate project with all of my other code. in my case I have a 3rd project that I targetted model builder to so that the model project is referenced by the umbraco project as well as the project with the controllers and other related logic.

    Looking at the docs, it looks to me that you are fine with the c# code in the AppCode folder because it is compiled and executed. The AppPlugins folder generally holds the manifest, and other files that are served to the browser like css, javascript, and html files

  • Allan Kirk 9 posts 99 karma points c-trib
    Mar 20, 2020 @ 08:36
    Allan Kirk
    0

    I think this is the correct setup rather than putting this file in the AppPlugins. I am just looking for confirmation if I am on the right track with this or if I am totally wrong the plugin controllers should in-fact be stored in the AppPlugins.

    This is not at all obvious from the Surface Controller page.

Please Sign in or register to post replies

Write your reply to:

Draft