【问题标题】:Loading 2 iframes at same time同时加载 2 个 iframe
【发布时间】:2012-07-23 14:35:02
【问题描述】:

我已经开始在 IIS 7 上的 .Net 4 中开发网络聊天。聊天主页包含 2 个 IFRAME。第一帧用于保留消息并逐步加载(它在用户连接到聊天时加载并传递消息以聊天)。第二个 iframe 用于发送消息。当第一帧加载第二帧无法加载但如果第一帧停止加载时秒数以毫秒为单位执行时,我遇到了问题。

  1. 我已经试过了:
  2. 使用 AJAX 发送消息。
  3. 对第一帧和第二帧的脚本使用不同的名称。它有时会有所帮助,但并非总是如此。
  4. 检查用户刷新聊天主页或关闭后脚本是否仍在运行。
  5. 在 IIS 中设置连接超时。
  6. 使用流式响应/文本响应。
  7. Connection keep-alive/no keep alive 指令。
  8. 交换主聊天页面的 iframe 标签。
  9. 以不同方式为聊天主页添加 CSS JS 文件,例如 @import CSS。
  10. 使用删除胎面。

我找到了一个解决方案,但我认为这不是使用多个域的好解决方案,因为域访问 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


    【解决方案1】:

    您是否考虑过查看 NuGet 中的 SignalR(测试版)包 - 它是为编写此类应用程序而定制的,并且与 Node.js 有相似之处。我强烈建议您考虑研究这项技术来解决这个问题。

    可以在 git hub https://github.com/SignalR/SignalR 和 Nuget http://nuget.org/packages/SignalR 上找到它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-26
      • 2013-06-21
      相关资源
      最近更新 更多