Why is the controller being repeatedly called?

4 posts, 0 answers
  1. Jim
    Jim avatar
    25 posts
    Member since:
    Mar 2016

    Posted 04 Apr Link to this post

    I set a break point in the constructor of my controller and I noticed that the controller is getting called several times on the startup of my project.

    In my _Layout I have a menu control setup like:

     @(Html.Kendo().Menu()

                .Name("myMenu")
                .Animation(a =>
                {
                    a.Open(o =>
                    {
                        o.Expand(ExpandDirection.Vertical);
                        o.SlideIn(SlideDirection.Down);
                        o.Fade(FadeDirection.In);
                    });
                })
                .HoverDelay(100)
                .Items(i =>
                {
                    i.Add().Text("Job Profiles")
                        .Items(child =>
                        {
                            child.Add().Text("Item 1").Action("Act1", "Home");
                            child.Add().Text("Item 2").Action("Act2", "Home");
                            child.Add().Text("Item 3").Action("Act3", "Home");                        
                            child.Add().Text("Item 4").Action("Act4", "BadController");

                            child.Add().Text("Item 5").Action("BadAction", "Home");
                        });
                })
            )

     

     

    So in my Home Controller I will see it being called 4 times.

    Why does this happen?  It's not like it's validating the action/controller at this time, because Item 4 and Item 5 should blow up. (It will blow up, but only when the user clicks on the items).

    This is causing poor performance due to initialization that I have occurring in the constructor.

     

    Please advise.

  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 06 Apr Link to this post

    Hello Jim,

    This may be related to the Menu security trimming, which is enabled by default. See the troubleshooting help topic for more information.

    Regards,
    Alex Gyoshev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Jim
    Jim avatar
    25 posts
    Member since:
    Mar 2016

    Posted 06 Apr in reply to Alex Gyoshev Link to this post

    In general should the initialization be taken out of the constructor?

    I can see by toggling the SecurityTrimming  the calls are reduced, but I would prefer not to disable it for fear that I'll forget to re-enable it on deployment.

  5. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 08 Apr Link to this post

    Hello Jim,

    The multiple calls are only triggered in debug mode -- in production, the authorization is cached. You can conditionally toggle the security trimming only in production mode, but in that case, you will not observe its behavior on the site.

    Regards,
    Alex Gyoshev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready