跟小D每日学口语

弹出窗口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
This article was previously published under Q196383

SYMPTOMS

When windows are opened from script in an HTML page using window.open or ShowModalDialog, Internet Explorer responds by prompting users to enter their username and password every time a new window is created. This happens even though the user already entered a correct username and password and successfully authenticated with the Web server.

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."

Back to the top

CAUSE

When asked to create new windows through script, Internet Explorer might create the window in the wrong Internet Explorer process. Because authentication credentials and the temporary cookies used for session identification are cached per process, new windows need to re-authenticate and start a new session if they don't open in the same process as their opening window.

This behavior can appear random; the determined process for new windows is dependent on several variables, including timing and browser configuration.

Back to the top

RESOLUTION

To resolve this problem, upgrade to the latest version of Internet Explorer or Microsoft Windows NT 4.0 Service Pack 6a (SP6a). You can download the latest version of Internet Explorer from the following Microsoft Web site:
http://www.microsoft.com/windows/ie/ (http://www.microsoft.com/windows/ie/)
Disabling the "Browse In New Process" browser setting in the Advanced tab of the Internet Options will alleviate most of the symptoms described in this article.

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.

Back to the top

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Internet Explorer 4.01 Service Pack 2 and Internet Explorer 5.

Back to the top

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:
      <%@ LANGUAGE="VBSCRIPT" %>
            <HTML><HEAD><TITLE>Test for Session ID</TITLE></HEAD>
            <BODY>
            ASP SESSION ID:
            <%= Session.SessionID %>
            <P>
            <FORM><INPUT TYPE=BUTTON ID=PushME onclick="return openwindow();"
            VALUE="WindowOpen"></FORM>
            <SCRIPT>
            function openwindow()
            {
            window.open("test.asp");
            }
            </SCRIPT>
            </BODY></HTML>
            
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.

Back to the top

REFERENCES

Similar symptoms can occur when working with Office documents or other Active Document servers in a Web environment.

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
185978 (http://support.microsoft.com/kb/185978/) FIX: Double GET requests and cookies are lost with Word 2000 or Excel 2000

 

原文: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就不会丢失了 
 

posted @ 2008-07-24 10:08  javak  阅读(2658)  评论(1编辑  收藏  举报