Copied to clipboard

Flag this post as spam?

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


  • Jahan 20 posts 52 karma points
    Nov 09, 2015 @ 19:52
    Jahan
    0

    Umbraco cannot find the route in backoffice

    Please look at my question that is in stackoverflow website Umbraco cannot find the route in backoffice

    Help me, please.

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Nov 10, 2015 @ 06:39
    David Brendel
    0

    Hi Jahan,

    SurfaceController are used only for frontend stuff in umbraco.

    If you want to use a controller in the backoffice have a look at UmbracoAuthorizedApiController.

    These are used in the backoffice to handle data fetching/updating.

    Also have a look at the PluginController attribute

    Regards David

  • Jahan 20 posts 52 karma points
    Nov 10, 2015 @ 11:40
    Jahan
    0

    Hi David, Please answer completely because I tested but I couldn't get a good result. Give me a correct URL. Someone has answered it but it's not useful for me.

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Nov 10, 2015 @ 12:15
    David Brendel
    100

    Hi Jahan,

    so your controller should look something like this:

    [PluginController("ReplyApi")]
    public class ReplyApiController : UmbracoAuthorizedJsonController
    {
         [HttpPost]
         public bool ReplyMessage(string message)
         {
             //Send your message here
             //Maybe return if it was a success - thus the bool return value, can also be void or what you need
         }
    }
    

    Also your controller is in the wrong place. AppPlugins only contains all the angularjs stuff. Instead put it in AppCode or in a Controller folder in your solution.

    Second the path to your api controller is wrong. I would suggest to use ServerVariables for these kind of paths.

    You can add ServerVariables during application startup:

    public class StartUp : IApplicationEventHandler
    {
         public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
         {
                ServerVariablesParser.Parsing += ServerVariablesParser_Parsing;
         }
    
    void ServerVariablesParser_Parsing(object sender, Dictionary<string, object> e)
            {
                if(HttpContext.Current == null) throw new InvalidOperationException("HttpContext is null");
                var urlHelper = new UrlHelper(new RequestContext(new HttpContextWrapper(HttpCo
    
    ntext.Current), new RouteData()));
    
            var dict = new Dictionary<string, object>();
    
            dict.Add("replyBaseUrl", urlHelper.GetUmbracoApiServiceBaseUrl<ReplyApiController>(controller => controller.ReplyMessage("")));
    
            if (!e.Keys.Contains("replyController"))
            {
                e.Add("replyController", dict);
            }
        }
    }
    

    With that you can use the path in your angular controller like so:

    Umbraco.Sys.ServerVariables.replyController.replyBaseUrl
    

    So your http call will look like this:

    $http.post(Umbraco.Sys.ServerVariables.replyController.replyBaseUrl + "ReplyMessage?message=" + textMessage) // Can not find this URL
            .then(function (response) {
                alert("YES!");
                //TODO: 
            });
    

    Hope that helps

  • Jahan 20 posts 52 karma points
    Nov 10, 2015 @ 18:58
    Jahan
    0

    THANK YOU VERY MUCH, David.

  • Jahan 20 posts 52 karma points
    Nov 10, 2015 @ 21:11
    Jahan
    0

    Hi David, Please visit this link. He answered simply and it's correct. What's your idea about it?

  • Matthieu Nelmes 102 posts 385 karma points
    Nov 10, 2015 @ 13:19
    Matthieu Nelmes
    0

    I've added some input on the StackOverflow post. I'd also recommend David's suggestion of using UmbracoAuthorizedJsonController instead of a SurfaceController.

  • Jahan 20 posts 52 karma points
    Nov 10, 2015 @ 21:13
    Jahan
    0

    Thank you.

  • 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