C# 中的帧重定向

发布于 2024-08-26 08:40:31 字数 1975 浏览 0 评论 0原文

我想从 IIS 7 的托管模块中用 C# 执行帧重定向。
当我调用 context.Response.Redirect(@"http://www.myRedirect.org"); 时,会显示正确的页面,但浏览器中也会显示地址。这正是我不想要的。
所以我想要这样的东西:

private void OnBeginRequest(object sender, EventArgs e)
{
    HttpApplication app = (HttpApplication)sender;
    HttpContext context = app.Context;

    // make a frame redirect if a specified page is called
    if (context.Request.ServerVariable["HTTP_REFERER"].Equals(@"http://www.myPage.org/1.html"))
    {
        // perform the frame redirect here, but how?
        // so something like
        context.Response.Redirect(@"http://www.myRedirect.org");
        // but as I said that doesn't redirect as I want it to be
    }
}

对此有什么想法吗?
编辑: 我尝试了这个例子,所以我有:

private void OnBeginRequest(object sender, EventArgs e)
{
    HttpApplication app = (HttpApplication)sender;
    HttpContext context = app.Context;

    // make a frame redirect if a specified page is called
    if (context.Request.ServerVariable["HTTP_REFERER"].Equals(@"http://www.myPage.org/1.html"))
    {
        // perform the frame redirect here, but how?
        context.Response.Write(@"<html>");
        context.Response.Write(@"<head>");
        context.Response.Write(@"</head>");
        context.Response.Write(@"<frameset rows=""100%,*"" framespacing=""0"" frameborder=""NO"" border=""0"">");
        context.Response.Write(@"<frame src=""http://www.myRedirect.org"" scrolling=""auto"">");
        context.Response.Write(@"</frameset>");
        context.Response.Write(@"<noframes>");
        context.Response.Write(@"<body>Some text...");
        context.Response.Write(@"</body>");
        context.Response.Write(@"</noframes>");
        context.Response.Write(@"</html>");
    }
}

但这也没有正确重定向。我的浏览器中仍然显示重定向地址。那么还有其他想法吗?

编辑: 我显然犯了一个错误。上面的代码可以工作并执行我想要的操作。它首先不起作用,因为我的重定向网址做了一些意想不到的事情。

I would like to execute a frame redirect in C# from my managed module for the IIS 7.

When I call context.Response.Redirect(@"http://www.myRedirect.org");the correct page is shown but also the address is shown in the browser. And that is exactly what I do not want.

So I want something like:

private void OnBeginRequest(object sender, EventArgs e)
{
    HttpApplication app = (HttpApplication)sender;
    HttpContext context = app.Context;

    // make a frame redirect if a specified page is called
    if (context.Request.ServerVariable["HTTP_REFERER"].Equals(@"http://www.myPage.org/1.html"))
    {
        // perform the frame redirect here, but how?
        // so something like
        context.Response.Redirect(@"http://www.myRedirect.org");
        // but as I said that doesn't redirect as I want it to be
    }
}

Any ideas about that?

EDIT:
I tried the example, so I have:

private void OnBeginRequest(object sender, EventArgs e)
{
    HttpApplication app = (HttpApplication)sender;
    HttpContext context = app.Context;

    // make a frame redirect if a specified page is called
    if (context.Request.ServerVariable["HTTP_REFERER"].Equals(@"http://www.myPage.org/1.html"))
    {
        // perform the frame redirect here, but how?
        context.Response.Write(@"<html>");
        context.Response.Write(@"<head>");
        context.Response.Write(@"</head>");
        context.Response.Write(@"<frameset rows=""100%,*"" framespacing=""0"" frameborder=""NO"" border=""0"">");
        context.Response.Write(@"<frame src=""http://www.myRedirect.org"" scrolling=""auto"">");
        context.Response.Write(@"</frameset>");
        context.Response.Write(@"<noframes>");
        context.Response.Write(@"<body>Some text...");
        context.Response.Write(@"</body>");
        context.Response.Write(@"</noframes>");
        context.Response.Write(@"</html>");
    }
}

But that also doesn't correctly redirect. I still have the redirect address shown in my browser. So any other idea?

EDIT:
I obviously made a mistake. The code above works and does what I want. It first didn't work because my redirect url was doing something unexpected.

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

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

发布评论

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

评论(1

南城旧梦 2024-09-02 08:40:31

要执行 框架重定向,您需要发回包含框架集的 HTML 代码单帧,其源设置为 http://www.myRedirect.org。就服务器和浏览器而言,没有发生重定向——它只是收到了一些 HTML 代码。

正如您所观察到的,执行 Response.Redirect 将会导致浏览器向新页面发出新的请求,并在标题栏中向用户显示新地址。它通常用于页面实际更改其地址,但所有者仍然希望可以从原始 URL 访问该页面的情况。

编辑:HTML框架重定向示例:http://en.wikipedia。 org/wiki/URL_redirection#Frame_redirects

To perform a frame redirect you need to send back the HTML code containing a frameset with a single frame, with it's source set to http://www.myRedirect.org. As far as the server and browser is concerned no redirect has happened - it's just received some HTML code.

Performing a Response.Redirect will, as you've observed, cause the browser to make a fresh new request to the new page, showing the user the new address in the title bar. It's typically used for when a page actually changes its address, but the owners still want it reachable from the original URL as well.

EDIT: HTML frame redirect sample: http://en.wikipedia.org/wiki/URL_redirection#Frame_redirects

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