I'm not sure how to search for what I'm looking for. All search terms that I attempt seem to return totally irrelevant results. So my apologies in advance if this is a dumb question, but if this is possible it seems like it would make some things much more efficient. I've inherited my first MVC website just over a year ago & I get around, but I still have much to learn.
When the user hits a URL in the browser, the "OnActionExecuting" method is called for the (CS) Controller and it does all of the verification of the user, permissions, etc. (I'm trying to keep this simple, but if you need more info, let me know) Then the "public ActionResult Index()" is called and it loads the CSHTML files and displays them to the user. At this point the CSHTML Page has access to some limited data that has been passed back for "ViewBag" (not sure if that is a common name for it, or setup by the previous programmer) settings.
Then the page calls it's (JavaScript) Controller. From what I've read, the JavaScript has no access to the "ViewBag" data or anything from the server at this point. The JS is then calling AJAX methods which exist back in the exact same (CS) Controller. It once again does all the exact same user/permission checks, then retrieves whatever data it is trying to retrieve.
So I guess my question is, is there either a way to pass back "every page" JSON data (like the user's name) so that it doesn't have to be retrieved, or is this doing something out of order by doing the initial data checks in the 1st place, or what? I abhor that so much functionality gets called multiple times to do the exact same thing. In fact, I haven't been testing this in this iteration, but if there were multiple AJAX called on every page (other than they should be merged if possible), it would perform the user/permission checks once per AJAX call.
Can someone help me understand what I am missing, please?