弹出窗口Session丢失,是什么原因?有没有办法解决?
一:有些杀病毒软件会去扫描您的Web.Config文件,那时Session肯定掉,这是微软的说法。
二:程序内部里有让Session掉失的代码,及服务器内存不足产生的。
三:程序有框架页面和跨域情况。
第一种解决办法是:使杀病毒软件屏蔽扫描Web.Config文件(程序运行时自己也不要去编辑它)
第二种是检查代码有无Session.Abandon()之类的。
第三种是在Window服务中将ASP.NET State Service 启动。
第四种:
使用window.showModalDialog进行信息的提示,相当方便,也容易控制外观和布局。但是存在一个严重的问题,就是Session丢失。当在A页面进行showModalDialog时,弹出的模态窗口open新页面或new dialog()时,会得不到A页面中的Session,这样就严重地限制了他的使用范围。
进一步的使用模式窗口可以发现session的丢失总是便随页面的刷新
1.在普通页面中弹出模式窗口且进行new dialog()操作时 会造成该进程中所有页面session的丢失
2.在模式窗口嵌套使用时 弹出的模式窗口并不会使父模式窗口的session丢失 但是会取不到父模式窗口的值
3.在弹出的模式窗口中使用js脚本需要验证表单时 如果出现return true or false之类的语句,会造成模态窗口session的丢失。
用showModalDialog经常出现这样那样奇怪的问题,因此最好少用showModalDialog。替代的方法就是用DIV来模拟实现模式窗口相同的功能。
官方解答:
FIX: Windows Opened by Script Lose Authentication or Session
Article ID | : | 196383 |
Last Review | : | June 21, 2004 |
Revision | : | 2.0 |
On This Page
SYMPTOMS
New windows may also lose Web server session information, creating a new session or reusing an older, incorrect session from a separate Internet Explorer instance.
Also, if the new window contains a Java applet that accesses static information from a class, it may not be able to share that information with an applet in another window.
These symptoms do not appear if the Windows Desktop Update is installed and the browser is not set to "Browse In New Process."
CAUSE
This behavior can appear random; the determined process for new windows is dependent on several variables, including timing and browser configuration.
RESOLUTION
However, Web servers should avoid relying on this as a solution. Web sites that expect users to change browser settings will have a negative user experience, particularly when other sites require a different value for the same settings. Users in corporate environments may not even have control over this setting. Furthermore, disabling "browse in new process" can affect the stability of the system shell and some users may need to use "Browse In New Process" when they are working with pages that contain a lot of Active Content.
Note that all session-managed pages should be set to expire immediately. Some session inconsistencies can result when pages are pulled from the cache rather than from the Web server.
STATUS
MORE INFORMATION
Steps to Reproduce Behavior
1. | Create the following Active Server Pages (ASP) page on an Internet Information Server machine, version 3.0 or later, in a scripts directory:
|
2. | Verify that the "Browse In New Process" setting is selected in Internet Explorer on the client machine. This setting is in the Browser Settings section in the Advanced tab of the Internet Options dialog box. |
3. | On the client machine, launch exactly one Internet Explorer instance. Navigate to the ASP page created in step 1. Click the "WindowOpen" button to execute window.open and create a new window. Note that the ASP Session ID matches in both child and parent window. |
4. | Create a new Internet Explorer instance by invoking Internet Explorer from the Start menu or Desktop icon. Again, navigate to the ASP page created in step 1. Click the "WindowOpen" button. Note that the ASP Session ID does not match in both child and parent window of the new process. In some cases, this may be the session ID of the first pair of Internet Explorer windows. |
REFERENCES
For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
原文:http://support.microsoft.com/default.aspx?scid=kb;EN-US;196383
第5种
从 HTML 模式或无模式对话框可能没有打开同一进程中 InternetExplorer 窗口中打开,因此模式窗口中调用 window.open()方法打开具体页面,可能造成session 丢失.例如:主窗体a.aspx,点击按钮时采用window.showModalDialog,打开弹出窗体b.aspx,b.aspx为模式窗体,然后在b.aspx窗体中再用window.open方式打开窗体c.aspx时,session会丢失。
解决方法:
思路: 调用 a.aspx window 的 open 方法打开
a.aspx 中window.showModalDialog 调用方法传递 dialogArguments属性为 window 对象
window.showModalDialog("b.aspx",window,"....") ;
b.aspx 中
var openobj = window;
if(typeof(window.dialogArguments) == "object")
{
openobj = window.dialogArguments;
}
openobj.open("c.aspx");
这样处理 c.aspx中 Session就不会丢失了
正面猛男