【发布时间】:2012-07-23 14:35:02
【问题描述】:
我已经开始在 IIS 7 上的 .Net 4 中开发网络聊天。聊天主页包含 2 个 IFRAME。第一帧用于保留消息并逐步加载(它在用户连接到聊天时加载并传递消息以聊天)。第二个 iframe 用于发送消息。当第一帧加载第二帧无法加载但如果第一帧停止加载时秒数以毫秒为单位执行时,我遇到了问题。
- 我已经试过了:
- 使用 AJAX 发送消息。
- 对第一帧和第二帧的脚本使用不同的名称。它有时会有所帮助,但并非总是如此。
- 检查用户刷新聊天主页或关闭后脚本是否仍在运行。
- 在 IIS 中设置连接超时。
- 使用流式响应/文本响应。
- Connection keep-alive/no keep alive 指令。
- 交换主聊天页面的 iframe 标签。
- 以不同方式为聊天主页添加 CSS JS 文件,例如 @import CSS。
- 使用删除胎面。
我找到了一个解决方案,但我认为这不是使用多个域的好解决方案,因为域访问 javascript 限制。 iFrames not executing in parallel
这里是Test.aspx和Test.aspx.cs页面代码:
<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="Test._Default" %>
using System;
using System.Web;
using System.Threading;
namespace Test
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string p = (Request.QueryString["p"] != null)?Request.QueryString["p"]:"";
if(Request.QueryString["data"] == null)
{
Response.Write(@"<html><head></head><body>12<iframe src=""Test.aspx?data="" height=""900px""></iframe><iframe src=""http://localhost/Test"+p+@".aspx?data="" height=""900px""></iframe></body></html>");
}
else
{
System.IO.File.AppendAllText(Server.MapPath(".")+ @"\test.log", DateTime.Now.ToString()+ "\t" + "Data script started\r\n");
Response.Write(new String(' ', 1024));
int i=0;
while (Response.IsClientConnected)
{
Response.Write((++i).ToString() + " ");
Response.Flush();
Thread.Sleep(1000);
System.IO.File.AppendAllText(Server.MapPath(".")+ @"\test.log", DateTime.Now.ToString()+ "\t" + "Data script Runned\r\n");
}
System.IO.File.AppendAllText(Server.MapPath(".")+ "test.log", DateTime.Now.ToString()+ "\t" + "Data script stoped\r\n");
}
}
}
}
【问题讨论】:
标签: c# asp.net html iframe iis-7