11.2 Session丢失问题
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FireFoxCookie.aspx.cs" Inherits="SupcanDemo.FireFoxCookie" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" src="binary/dynaload.js?107"></script> <script> //这是 asp.net 的 SessionId 在 Cookie 中的固定写法 window.$sid = 'ASP.NET_SessionId=<%= System.Web.HttpContext.Current.Session.SessionID %>'; </script> ...如果您后端是Java, 那么修改 JSP:
... </script> window.$sid = 'JSESSIONID=<%=request.getSession().getId()%>;Path=<%=request.getContextPath()%>'; </script>
... function bldStr(ctlType, id, para) { var w = window; ... str += '<param Name="Cookie" Value="' +w.$sid+ '">'; str += '<param Name="CtlPara" Value="' +para+ '"></Object>'; ...
function OnReady(id) { // ASP.Net 是: AF.func("setCookie", "ASP.NET_SessionId=<%= System.Web.HttpContext.Current.Session.SessionID %>"); // JSP 是: AF.func("setCookie", "JSESSIONID=<%=request.getSession().getId()%>;Path=<%=request.getContextPath()%>"); ...
二种方法的内部实现有轻微的差异, 您可以实际测一下, 挑选更适合自己的方法;
也可以参考 硕正官网 主页左侧上方的"后端开发案例"中的文章 Firefox/Chrome中硕正请求Session丢失解决方法.