2

我对南希很陌生,所以希望我只是在这里做一些愚蠢的事情。我有一个 nancy 服务,我正在发布这样的数据:

$.ajax({
    type: 'POST',
    url: url,
    data: JSON.stringify({
        searchTerm: productSearchTerm,
        pageSize: pageView.PageSize(),
        selectedBrands: pageView.checkedBrands(),
        pageNumber: pageView.CurrentPage(),
        selectedCategories: pageView.checkedCategories(),
        selectedGender: pageView.checkedGender(),
        SelectedColours: pageView.checkedColour(),
        saleItemsOnly: pageView.saleItemsOnly(),
        selectedMinimumPrice: pageView.minPrice(),
        selectedMaximumPrice: pageView.maxPrice()
    }),
    contentType: "application/json; charset=utf-8",
    dataType: 'json'
})
    .done(function (data) {
        bindSearchResult(data);
    })
    .fail(function (a) {
        console.log(a);

    });

然后在服务中,我需要为来自用户的未来请求保留一堆字符串值,我正在这样做:

    private void AddListOfStringToIsSessionNull(string name, IEnumerable<string> data)
    {
        if (Session[name] == null)
        {
            Session[name] = data.ToList();
        }
    }

这些似乎设置了会话变量,并且当我在返回页面后检查页面时会出现“_nc”cookie。

但是,如果我然后 F5 页面,则会话项在服务器上再次全部为空。

我已经排除了跨站点发布,因为它们都在同一个域上。

这可能是 AJAX 的事情吗?似乎不太可能,因为这似乎是一件非常标准的事情。或者你不能在 POST 上设置它吗?如果是这样,有没有办法解决这个问题?

如果有人可以提供帮助,我将永远感激不已,否则我将不得不重新在 WCF 中编写此内容,这将使我从窗口中猛扑过去 :)

非常感谢。

编辑

  • 在 Chome 中打开一个新的隐身窗口我点击主页,没有 nancy cookie 存在(这是正确的)
  • 输入一个搜索词,它会回调和 AJAX 发布并抓取 JSON,还会在 Nancy Session 中弹出一个字符串列表
  • 检查 cookie,一个 nancy 出现了,回发时会话值是正确的:

      npTBnqPp99nLd5fU0%2btJbq%2fY%2bdf2UFWTaq5D28Az7Jw%3dzF8cIHNxTWX399sbmowjheho2S29ocpKs1TXD51BrbyPPNCeLfAcYqWhkRHqWdwKJNED5kuspllIjhI5rf2W6NKtf8xo68BlF5eLLgJxMtAxw2yD2ednEzUazq1XBt2Id77t5LE5tZVwkpRGDT5b9J0nQnr9zfzCOALXb2hQQGBPkMVyNNTO24pW1UC6Uda3B86LLYA02Jgy4G9DiT6KsutR3pSXO8AZFOlcmAEHbSSX9A8FAHaL ... etc.
    
    • 然后我搜索一个不同的搜索词,它调用这段代码:--Session.DeleteAll();
    • 使用新数据重新填充 nancy 会话并返回到浏览器

但是此时 cookie 尚未使用新值更新,它仍然如下所示:

    npTBnqPp99nLd5fU0%2btJbq%2fY%2bdf2UFWTaq5D28Az7Jw%3dzF8cIHNxTWX399sbmowjheho2S29ocpKs1TXD51BrbyPPNCeLfAcYqWhkRHqWdwKJNED5kuspllIjhI5rf2W6NKtf8xo68BlF5eLLgJxMtAxw2yD2ednEzUazq1XBt2Id77t5LE5tZVwkpRGDT5b9J0nQnr9zfzCOALXb2hQQGBPkMVyNNTO24pW1UC6Uda3B86LLYA02Jgy4G9DiT6KsutR3pSXO8AZFOlcmAEHbSSX9A8FAHaL.... etc.

我还需要做些什么来解决这个问题吗?

4

1 回答 1

0

So my issue was me being a bit daft really, the implementation of the cookie stuff works well, however there were occasions when I was stuffing too much into the cookie and pushing it over the 4K cookie limit.

This meant that I was seeing some inconsistent behavior where sometimes the cookie worked nicely (the cookie was < 4K) where as for some search terms too much was being written into the cookie which meant either the cookie was never created or it was not overwriting the existing cookie.

So yes, my fault, but thought this answer might aid someone as silly as me trying to store the world in a cookie..

Right I'm off to write a session provider.

于 2013-11-19T15:40:31.797 回答