在http请求之前制作真正的闪屏

发布于 2024-12-10 11:10:51 字数 223 浏览 0 评论 0原文

我需要制作一个 C# 启动屏幕,该屏幕将在调用 default.aspx 之前启动。

当我浏览我的 URL 时,我可以看到 IE 8.0 消息 waiting for http://xxxxx 并出现空白屏幕,并且在一段时间内我的第一页已完全加载。我如何处理\拦截该消息,以便在建立连接之前显示我的启动屏幕?

我尝试过使用 HttpListener 但它似乎不是正确的方法。

I need to make a C# splash screen that will be started before default.aspx is called.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

意中人 2024-12-17 11:10:51

在浏览器联系您的网站之前,您无法显示网站的某些内容。

可以做的是在网站的根目录下创建一个轻量级的起始页面(加载速度很快),然后重定向到一个较重的“真实”页面。

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.

懷念過去 2024-12-17 11:10:51

您可以关闭输出缓冲来执行您要求的操作,但“等待代码”上的内容不得使用正在加载的任何其他资源。沟通也会变得更加健谈。

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>

隐藏代码:

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>");
        }
    }
}

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:

<%@ 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>");
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文