简体   繁体   English

在HTTP请求之前制作真实的启动屏幕

[英]Make real Splash Screen before http request

I need to make a C# splash screen that will be started before default.aspx is called. 我需要制作一个将在调用default.aspx之前启动的C#启动屏幕。

When I browse to my URL, I can see the IE 8.0 message waiting for http://xxxxx with a blank screen, and in some time my first page is fully loaded. 当我浏览到URL时,可以看到IE 8.0消息waiting for http://xxxxx空白屏幕的waiting for http://xxxxx ,并且有时我的第一页已完全加载。 How can I handle\\intercept that message, in order to show my splash screen until the connection is established? 我如何处理\\拦截该消息,以便在建立连接之前显示初始屏幕?

I've tried using HttpListener but it doesn't seem to be the right way. 我试过使用HttpListener,但这似乎不是正确的方法。

You can't show something of your site before the browser contacts your site. 在浏览器联系您的网站之前,您无法显示网站的某些内容。

What you can do is have a lightweight start page (that loads quickly) at the root of your site and then redirect to a heavier "real" page. 可以做的是在网站的根目录中创建一个轻量级的起始页面(快速加载),然后重定向到较重的“真实”页面。

You can turn output buffering off to do something like you ask but the content on the "waiting code" must not be using any of the other resources being loaded. 您可以关闭输出缓冲以执行类似您要求的操作,但是“等待代码”上的内容一定不能使用正在加载的任何其他资源。 The communication will also become more chatty. 交流也将变得更加健谈。

aspx-page: aspx页:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BufferingResponse.Default" %>

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Waiting...
    </div>
    </form>
</body>
</html>

Code behind: 后面的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BufferingResponse
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Context.Response.BufferOutput = false;

            // simulate some work...
            System.Threading.Thread.Sleep(5000);

            Response.Write("<div>Another response five seconds later...</div>");
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM