我有以下代码在起作用:
public JsonResult AddTicketToCart(...)
{
...
Session.Add("Cart", cart);
return Json(new { IsSuccess = true }, JsonRequestBehavior.AllowGet);
}
在 JS 代码中:
$.get('/desk/AddTicketToCart', { clientId: clientId, sessionId: sessionId, levelId: levelId, places: places, isWithoutPlace: isWithoutPlace, delivery: delivery }, function (data) {
if (data.IsSuccess) {
if (isQuickBuy)
window.location = '/desk/paywizard';
else
window.location = $('#wiz_header .first-child>a').attr('href');
} else {
toastr.options.timeOut = 10000;
toastr.error('Error.');
}
});
该PayWizard
动作包含:
if (Session["Cart"] == null)
return new HttpNotFoundResult();
var model = CreateViewData<PersonalInfoViewData>();
return View("PersonalInformation", model);
问题在于我在 Ipad 上收到 404 错误。在桌面上一切正常。我将日志消息添加到AddTicketToCart
:
public JsonResult AddTicketToCart(...)
{
...
Session.Add("Cart", cart);
if(Session["Cart"] != null)
Logging.Log.Info("Cart not null");
else
Logging.Log.Info("Cart equal null");
var test = (CartModel) Session["Cart"];
if( test != null)
{
Logging.Log.Info("CartModel not null");
Logging.Log.Info("Tickets count: {0}", test.Tickets.Count);
}
else
Logging.Log.Info("CartModel equal null");
return Json(new { IsSuccess = true }, JsonRequestBehavior.AllowGet);
}
输出如下:
2012-11-02 09:37:34.4887 | Info | Cart not null
2012-11-02 09:37:34.4887 | Info | CartModel not null
2012-11-02 09:37:34.4887 | Info | Tickets count: 1
如您所见Cart
,会话中存在。ButinPaywizard
等于 null。哪里有问题?