Copied to clipboard

Flag this post as spam?

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


  • J 447 posts 864 karma points
    Apr 27, 2021 @ 14:55
    J
    0

    Custom Section using cshtml?

    I have created a custom section using this article as a guide

    https://www.enkelmedia.se/blogg/2013/11/22/creating-custom-sections-in-umbraco-7-part-1/

    Is it possible for me to use cshtml files instead of HTML/Angular? If so can anyone provide me with any guide?

    Thanks

  • Brendan Rice 538 posts 1102 karma points
    Apr 27, 2021 @ 16:52
    Brendan Rice
    1

    This isn't possible J. The back office is built on AngularJS and doesn't support cshtml.

  • J 447 posts 864 karma points
    Apr 28, 2021 @ 09:15
    J
    0

    @Brendan - Thank you

    In that case, I've been searching around for an example where i have a HTML and AngularJS page within the app_plugins folder. It loads as expected and shows the HTML page as per the link.

    If i wanted to carry out some codebehind operation such as getting some value from a database or read a config file (which i would use C# for) how would i go about achieving the same?

  • Huw Reddick 1932 posts 6722 karma points MVP 3x c-trib
    Apr 28, 2021 @ 09:51
    Huw Reddick
    1

    You will need to do either a post or get using is and call the method in your controller

  • J 447 posts 864 karma points
    Apr 28, 2021 @ 10:13
    J
    0

    Oh....any examples you could lead me to so i get an idea of what/where im doing all this? Thx

  • Brendan Rice 538 posts 1102 karma points
    Apr 28, 2021 @ 10:20
  • J 447 posts 864 karma points
    Apr 28, 2021 @ 12:50
    J
    0

    Thanks, im working my way through and have hit a snag.

    When i visit

    localhost:1234/umbraco/backoffice/My/PersonApi/GetAll

    I initially got an error which was resolved by logging in. I then got an error 'The requested resource does not support http method 'GET'' I surrounded it with [HttpGet]

    Now i get HTTP/1.1 417 Missing token

    To really narrow this down i decided to create a simple method as below

         [HttpGet]
         public string SayHello()
            {
                return "Hello World";
            }
    

    That too gives the same 417 error. I cleared my cache/history but the same error.

    Am i missing something?

  • Brendan Rice 538 posts 1102 karma points
    Apr 28, 2021 @ 13:42
  • J 447 posts 864 karma points
    Apr 28, 2021 @ 15:39
    J
    0

    Hi

    Yes i have seen that thread and nothing really worked on what was mentioned.

    Here is the code in a new class library and what im doing. Ive read the threads so have upgraded to Umbraco 7.5 where i feel most bugs were ironed out (Essentially a fresh copy of this install).

    using System.Web.Http;
    using Umbraco.Web.Editors;
    
    namespace Test
    {
        [Umbraco.Web.Mvc.PluginController("Notes")]
        public class HelloController : UmbracoAuthorizedJsonController
        {
            [HttpGet]
            public string SayHello()
            {
                return "Hello World";
            }
        }
    }
    

    My URL is

    http://localhost/umbraco/backoffice/notes/hello/sayhello

    At first i got authentication denied but after logging in that error went away and several attempts later i either see ERRCONNECTIONREFUSED in Chrome or in Fiddler i see

    The connection to 'localhost' failed.
    Error: ConnectionRefused (0x274d).
    System.Net.Sockets.SocketException No connection could be made because the target machine actively refused it 127.0.0.1:80

    Just working on that error but as soon as Fiddler is closed i see the above

  • J 447 posts 864 karma points
    Apr 28, 2021 @ 16:08
    J
    0

    I will leave the above code as is but what got it working was changing

    UmbracoAuthorizedJsonController

    to

    UmbracoAuthorizedApiController

    Hopefully this is the correct way!!??

  • Brendan Rice 538 posts 1102 karma points
    Apr 28, 2021 @ 16:34
    Brendan Rice
    0

    Glad you got it working

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies