开发者

Session State Issue

When visiting a page, I am storing a value in session state. When I click back on the browser, the value in session reverts to its original value. Why does this happen? I am not resetting the value when i go back.

This happens on iPhone and iPad - all other browsers do NOT roll back the session state value.

Thanks in advance.

I am using this javascript code (code in both pages is identical):

function pageLoad() {
    // Get the current url path
    var url = document.URL;

    PageMethods.IsNavigatingBackward(url, handleCallback);
}

function handleCallback(isBackward) {
    if (isBackward) {
        // Go back to previous page
        h开发者_如何学Pythonistory.back();
    }
    else {
        // Set the current url in the session
        var url = document.URL;

        PageMethods.SetCurrentPage(url, getLocation);
    }
}

And the code behind:

[WebMethod]
public static bool IsNavigatingBackward(Uri url)
{
    string currentPath = url.LocalPath;
    string lastPath = (string)HttpContext.Current.Session["LastPage"];
    bool isBackward = false;

    NavigationList table = NavigationList.GetInstance();

    if (table.IsBackwardNavigation(currentPath, lastPath))
    {
        isBackward = true;
    }

    return isBackward;
}

[WebMethod]
public static void SetCurrentPage(Uri url)
{
    HttpContext.Current.Session["LastPage"] = url.LocalPath;
}


You will only see the new session state value if the browser is:

  • Accepting cookies
  • Not showing you the cached original page

If both are these are true and assuming you're not reverting the value somewhere on the second page load, you will see the session state.

It would appear iPhone and iPad are not doing this.


I think you are misunderstanding what's going on. More than likely, the page is not being re-downloaded (and thus the session is not actually being set to anything). it's just using the previously cached downloaded page.


Can you try using the following instead:

[WebMethod(EnableSession = true)]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜