新建如下三个测试页面,
问题:
1、test2页面打开test3页面时,在test3页面里取不到session,如何解决?
2、通过test1页面同样是调用popupWindowHandle.testto(),和test2页面调用testto(),为何前者打不开正确的链接?(变为sys/test3.aspx)
3、如果将testto()中的window.open("test3.aspx",'_blank')替换为:
var Http = new ActiveXObject("Microsoft.XMLHTTP");
Http.open("GET","test3.aspx",false);
Http.send();
var str = Http.responseText;
发现popupWindowHandle.testto()调用xmlhttp可以发送正确(说明发送连接还是zkgl/test3.aspx),这是什么原因,open方式和xmlhttp发送有何不同?----------------------------------------------------
aspnet/sys/test1.aspx
aspnet/zkgl/test2.aspx
aspnet/zkgl/test3.aspx---------------------------------------------------
test1.aspx:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test1.aspx.cs" Inherits="aspnet_sys_test1" %><!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>test1</title>
</head>
<body>
<%
Session["test"] = "haike";
%>
<script type="text/javascript">
//打开非模态窗口
var popupWindowHandle;
if (!popupWindowHandle||popupWindowHandle.closed)
{
var winparms;
var rtnArray;
var frameWidth = 400;
var frameHeight =400;
winparms = "dialogHeight:"+ frameHeight +"px;";
winparms+= "dialogWidth:"+ frameWidth+"px;";
winparms+= " center: Yes; help: No; resizable: No; status: No;"; popupWindowHandle = window.showModelessDialog("../zkgl/test2.aspx",window,winparms); }
function totest()
{
if (popupWindowHandle && !popupWindowHandle.closed)
{
if(typeof(popupWindowHandle.testto) != "undefined")
{
popupWindowHandle.testto();
//alert(popupWindowHandle.document.location.href);
//alert(popupWindowHandle.obj.document.location.href);
}
}
}
function getsession()
{
alert("<%=Session["test"]%>");
}
</script>
<input type="button" value="打开窗体" onclick="totest();" />
<input type="button" value="获取session" onclick="getsession();" />
</body>
</html>------------------------------------------------------------
test2.aspx:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test2.aspx.cs" Inherits="aspnet_zkgl_test2" %><!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>test2</title>
</head>
<body>
<script type="text/javascript">
//取得主窗口对象
var mw = window.dialogArguments;
var obj;
function testto()
{
obj = window.open("test3.aspx","_blank");
//alert(document.location.href);
//alert(mw.document.location.href);
//alert(obj.document.location.href);
}
function getsession()
{
alert("<%=Session["test"]%>");
}
</script>
<input type="button" value="打开窗体" onclick="testto();" />
<input type="button" value="获取session" onclick="getsession();" />
</body>
</html>------------------------------------------------------------
test3.aspx:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test3.aspx.cs" Inherits="aspnet_zkgl_test3" %><!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>test3</title>
</head>
<body>
<script type="text/javascript">
//取得主窗口对象
var op = window.opener;
function getsession()
{
//alert(document.location.href);
//alert(op.document.location.href);
alert("<%=Session["test"]%>");
}
</script>
<input type="button" value="获取session" onclick="getsession();" />
</body>
</html>
问题:
1、test2页面打开test3页面时,在test3页面里取不到session,如何解决?
2、通过test1页面同样是调用popupWindowHandle.testto(),和test2页面调用testto(),为何前者打不开正确的链接?(变为sys/test3.aspx)
3、如果将testto()中的window.open("test3.aspx",'_blank')替换为:
var Http = new ActiveXObject("Microsoft.XMLHTTP");
Http.open("GET","test3.aspx",false);
Http.send();
var str = Http.responseText;
发现popupWindowHandle.testto()调用xmlhttp可以发送正确(说明发送连接还是zkgl/test3.aspx),这是什么原因,open方式和xmlhttp发送有何不同?----------------------------------------------------
aspnet/sys/test1.aspx
aspnet/zkgl/test2.aspx
aspnet/zkgl/test3.aspx---------------------------------------------------
test1.aspx:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test1.aspx.cs" Inherits="aspnet_sys_test1" %><!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>test1</title>
</head>
<body>
<%
Session["test"] = "haike";
%>
<script type="text/javascript">
//打开非模态窗口
var popupWindowHandle;
if (!popupWindowHandle||popupWindowHandle.closed)
{
var winparms;
var rtnArray;
var frameWidth = 400;
var frameHeight =400;
winparms = "dialogHeight:"+ frameHeight +"px;";
winparms+= "dialogWidth:"+ frameWidth+"px;";
winparms+= " center: Yes; help: No; resizable: No; status: No;"; popupWindowHandle = window.showModelessDialog("../zkgl/test2.aspx",window,winparms); }
function totest()
{
if (popupWindowHandle && !popupWindowHandle.closed)
{
if(typeof(popupWindowHandle.testto) != "undefined")
{
popupWindowHandle.testto();
//alert(popupWindowHandle.document.location.href);
//alert(popupWindowHandle.obj.document.location.href);
}
}
}
function getsession()
{
alert("<%=Session["test"]%>");
}
</script>
<input type="button" value="打开窗体" onclick="totest();" />
<input type="button" value="获取session" onclick="getsession();" />
</body>
</html>------------------------------------------------------------
test2.aspx:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test2.aspx.cs" Inherits="aspnet_zkgl_test2" %><!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>test2</title>
</head>
<body>
<script type="text/javascript">
//取得主窗口对象
var mw = window.dialogArguments;
var obj;
function testto()
{
obj = window.open("test3.aspx","_blank");
//alert(document.location.href);
//alert(mw.document.location.href);
//alert(obj.document.location.href);
}
function getsession()
{
alert("<%=Session["test"]%>");
}
</script>
<input type="button" value="打开窗体" onclick="testto();" />
<input type="button" value="获取session" onclick="getsession();" />
</body>
</html>------------------------------------------------------------
test3.aspx:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test3.aspx.cs" Inherits="aspnet_zkgl_test3" %><!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>test3</title>
</head>
<body>
<script type="text/javascript">
//取得主窗口对象
var op = window.opener;
function getsession()
{
//alert(document.location.href);
//alert(op.document.location.href);
alert("<%=Session["test"]%>");
}
</script>
<input type="button" value="获取session" onclick="getsession();" />
</body>
</html>
解决方案 »
- GridView 多表绑定问题,谢谢
- 网站被黑是什么原因呢。SQL注入也加了.哪位大哥大姐说下下~~~~~~~~~~~
- 新建ASP.net项目时出现IIS错误。100分,在线等。
- 问一个愚蠢的问题?
- 关于ASP.NET开发中的界面技术?
- 出售服务器,服务器空间
- 关于两个 DropDownList的连动问题 再请高手帮下忙
- aspnet_state检查报错怎么办?
- 送分~~~
- 一个自付宝生活号的问题-数据签名
- 在ASP.NET中的绘制地图的问题,不用JS怎么实现
- 求助--------------------------菜鸟的2个水晶报表问题--------------------------------
2.试试绝对路径呢?
在test1.aspx的
<body>
<%
Session["test"] = "haike";
%>
{
/*var obj0 = window.open("test3.aspx?act=0",'0');//,"_blank");
var obj1 = window.open("test3.aspx?act=1",'1',"_blank");
var obj2 = window.open("../zkgl/test3.aspx?act=2",'2');
var obj3 = window.open("../zkgl/test3.aspx?act=3",'3',"_blank");*/
window.open("http://<%=Request.Url.Authority.ToString()%>/aspnet/zkgl/test3.aspx");
}
以上语句均 不行
模态窗口里用window.open打开的窗口将新开一个Session会话
在首页main用 window.showModalDialog 或者 window.showModelessDialog 打开模态窗口A
再在A窗口里用 window.open 打开B
结果,我们发现 B 和 main 窗口的 SessionId 是不一样的,也就是说 B 窗口已经是开启一个新的session会话了。
-------------特此记录 JoeCom 2006-08-18
============================的确如此 sessionid不同~~~~但是假如在B页面重新在设置一下session的值
即时只是session["test"]=session["test"];
也可以在B页面获取session 只是是新的popupWindowHandle.testto(); 中
另外 用相对路径xmlhttp正确 而 open错误是怎么回事? function testto()
{
window.open("test3.aspx");---------返回 http://IP:PORT/aspnet/sys/test3.aspx 错误
var Http = new ActiveXObject("Microsoft.XMLHTTP");
Http.open("GET","test3.aspx",false);
Http.send();
var str = Http.responseText;
alert(str); -------------能返回页面 说明指向http://IP:PORT/aspnet/zkgl/test3.aspx
}
-------------------------
不代表session不同
{
//alert(document.location.href);
//alert(op.document.location.href);
alert(" <%=Session["test"]%>");
}
session这样取应该取不到吧
session 有时候能取到 有时候又会取不到?(发现很多网上的文章有类似的问题)
但是原session肯定没有丢
sessionid不同我觉得这个session对项目而言论大概也没有意义了可以取到 只是一次加载的值 需要刷新页面才能继续//我在test3.aspx.cs的page_onload函数内同样response.write这部分信息 也是得不到session
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["UserID"] = "Hello World";
}
Response.Write(Session.SessionID.ToString());
}
主页面html:
<asp:Button ID="Button2" runat="server" Text="打开新页" OnClientClick="return fun()" />
主页面js:
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function fun()
{
var Url='Default2.aspx';
window.open(Url,'ModalChild','dependent=yes,height=600, width=800, toolbar=no, menubar=no, scrollbars=yes, resizable:no,location=no, status=no');
return false;
}
</script>
</head>
新页面cs:
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
if (HttpContext.Current.Session["UserID"] != null)
{
Response.Write("session:"+Session["UserID"].ToString());
Response.Write("sessionId:" + Session.SessionID.ToString());
}
}
新页面html:
<asp:Button ID="Button1" runat="server" Text="session" OnClick="Button1_Click" />
你测试的我也可以通过不过我的测试不是这样的我现在的测试是这样的:A页面设置Session ,并以window.showModelessDialog方式打开B页面,
B页面再以window.open打开C页面,在C页面取不到Session
(不过如果B是以window.showModelessDialog方式打开C,则C可以取得Session)
还有谁能解答一下我后面提出的open和xmlhttp方式打开和发送相当路径页面导致的不同结果
B页面再以window.open打开C页面,在C页面取不到Session
------------------------------------
这样的操作好像不太友好,有点麻烦