登台服务器上的LocalStorage为空。 IIS7

时间:2015-03-02 06:38:19

标签: jquery asp.net-mvc html5

虽然让页面闲置很长时间,比如说10-15分钟,页面上的localstorage显示为“null'。

我的代码就是那个

LocalStorageFunc函数正在调用文档。

function LocalStorageFunc(MenuTitle, LinkName) {
   // alert('MenuTitle--' + MenuTitle + 'LinkName----' + LinkName);
    localStorage.setItem("PageTitle", MenuTitle);
    localStorage.setItem("PageName", LinkName);
}

我没有找到任何特殊原因,为什么localStorage值为页面名称和页面标题获取null。虽然我从来没有打开带有多个标签的页面,但登录用户的会话也不会过期。 Browser: chrome latest version

enter image description here

  $(document).ready(function () {
        if (localStorage.getItem("PageTitle") != null || localStorage.getItem("PageName") != "") {
            $("#pageTitle").text(localStorage.getItem("PageTitle"));
            $("#PageName").text(localStorage.getItem("PageName"));
        }
    });

  [1]: http://i.stack.imgur.com/XDalx.png


/*---------------------Menu Creation----------------------*/
$(document).ready(function () {
    var data = {
        "MenuLinks": [
            {
                "Title": "Configuration",
                "Fav": 0,
                "Pages": [
                    { "Name": "Define Manufacturer Inventory", "Link": "/Pages/InstallationAndCommissioning/MeterInventory/MeterMaster.aspx" },
                    { "Name": "Entity Configuration", "Link": "/EntityConfiguration/Index" },
                    { "Name": "Substation Configuration", "Link": "/SubStationConfiguration/Index" },
                    { "Name": "Firmware Upgradation", "Link": "/FirmwareUpgradation/Index" },
                    { "Name": "Define Meter Model", "Link": "/Pages/InstallationAndCommissioning/ModbusMeterModal/MODBUSMeterModalLibrary.aspx" }
                ]


            },
            {
                "Title": "Revenue Management",
                "Fav": 0,
                "Pages": [
                    { "Name": "Add Tariff", "Link": "/AddTariff/Index" },
                    { "Name": "Define Tariff", "Link": "/DefineTariff/Index" }
                ]
            },
            {
                "Title": "User Management",
                "Fav": 0,
                "Pages": [
                    { "Name": "Define User", "Link": "/Pages/UserManagement/DefineUsers.aspx" },
                    { "Name": "Change Password", "Link": "/Pages/UserManagement/ChangePassword.aspx" },
                    { "Name": "Manage Business Role", "Link": "/Pages/UserManagement/AddEditBusinessRoles.aspx" },
                    { "Name": "Assign Business Role to User", "Link": "/Pages/UserManagement/SearchUserForAssignBusinessRole.aspx" }
                ]
            },
            {
                "Title": "Virtual Group",
                "Fav": 0,
                "Pages": [
                    { "Name": "Create Virtual Group", "Link": "/VirtualGroupManagement/AddRule" }
                ]

            }
        ]
    };
    var exp;
    var tempI = 0;
    var i = 0;
    for (; i < data.MenuLinks.length; i++) {

        if (i % 2 == 0) {

            exp = $(
                "<div class='item' id='" +
                +i + "a"
                + "'>");
            exp.appendTo("#carouselwrapper");
            tempI = i;
        }

        var j = 0;
        for (; j < data.MenuLinks[i].Pages.length; j++) {
            var MenuTitle, SubMenuName, SubMenuLink;
            MenuTitle = data.MenuLinks[i].Title;

            SubMenuName = data.MenuLinks[i].Pages[j].Name;
            SubMenuLink = data.MenuLinks[i].Pages[j].Link;

            if (j == 0) {
                exp = $("<div class='MenuTitle' >"
                    + MenuTitle
                    + "</div>");
                exp.appendTo("#" + tempI + "a");
            }

            AppPath = $('#hdnAppPath').val();

            var xPath = "http://" + AppPath + SubMenuLink;;

            exp = $("<div class='MenuItemDiv'>\
                          <a class='MenuItemLink' href='" + xPath + "' target='_self' onClick='OpenLinkPage("
                + '"' + MenuTitle + '",'
                + '"' + SubMenuName + '",'
                + '"' + SubMenuLink + '"'
                + ");' class='pageLink' id='"
                + SubMenuName
                + "'>"
                + SubMenuName
                + "</a></div>");
            exp.appendTo("#" + tempI + "a");

        }
    }
});
/*---------------------Open Page Link----------------------*/
function OpenLinkPage(MenuTitle, LinkName, LinkHref) {

    var path11;

    path11 = 'http://' + AppPath + LinkHref;


    LocalStorageFunc(MenuTitle, LinkName);
    SaveFavRecentLinkInDB(MenuTitle, LinkName, path11, 'R');

    var path11;
    path11 = 'http://' + AppPath + LinkHref;
    // window.open(path11, "_self");
    addRecentLink(MenuTitle, LinkName, LinkHref);
    window.location.href = path11;
    event.preventDefault();

}

在页面加载时创建菜单项,然后单击菜单以更新本地存储值

![在此输入图片说明] [2]

0 个答案:

没有答案