Copied to clipboard

Flag this post as spam?

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

  • wilenx 16 posts 66 karma points
    Dec 25, 2013 @ 17:04

    Weird REST/Base behavior ...

    Hello all !

    In my site, a user is being saved in the Session object. And so, in my master template I decide whether to show the login or logout buttons based on the existence of an object in the Session. This works fine.

    Now, for a logged in user, I have JS script that runs every 10 seconds to call a base method and get a JSON response object with some user specific details. (This is used to update a span element with that data).

    It all works fine when it works ... It seems that every time the App_Data/TEMP folder is being touched (by me or by the umbraco engine after changing some code somewhere) it makes the umbraco engine to retrieve a CACHED version of a JSON response object, so that a JS timered request doesn't truly get to my code, and so I end up with corrupted data being returned to the JS.

    As you can see in my Base code, I first check if the user is connected. The user IS connected, and I still get a "Success=false". The IsUserConnected function works well, no problem there.

    How I manage to determine the data returned from the Base is not good and cached is with examining the response and seeing that the JSON object doesn't hold a newly added dummy field. Moreover, I've debugged the project and didn't stopped at the breakpoint defined at the GetPlayersBalace() first line of code.

    Does anyone encountered with this behavior ? What else can I do to fix that ?

    Base code:

    public class AccountingAPI : BaseRest
        [RestExtensionMethod(ReturnXml = false, AllowAll = true)]
        public static string GetPlayersBalace()
            if (!IsUserConnected)
                return BpSysTools.JS_WrapJSON(new
                    Success = false,
                    CurrencySymbol = string.Empty,
                    Balance = -1,
                    ErrorMessage = GetDictionaryItem("Noty_NotLoggedIn")
            // Get the user's balance and return a JSON object with Success=true with the data
            // (or false with the appropriate error message)

    My JS script:

    $(document).ready(function () {
    function updateBalanceLoop() {
        var spanCurrentUsername = $('#spanCurrentUsername');
        var spanCurrentCurrencySymbol = $('#spanCurrentCurrencySymbol');
        var spanCurrentBalance = $('#spanCurrentBalance');
            url: "/Base/AccountingAPI/GetPlayersBalace",
            cache: false,
            dataType: 'json',
            success: function (response) {
                if (response.Success) {
                    setTimeout(updateBalanceLoop, 10000);
                else {
                    // notify the user
Please Sign in or register to post replies

Write your reply to: