我想在IIS 7的托管模块中执行C#中的帧重定向。
当我呼叫context.Response.Redirect(@"http://www.myRedirect.org");
时,显示正确的页面,但地址显示在浏览器中。这正是我不想要的。
所以,我想是这样的:在C中的帧重定向#
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>");
}
}
但也不能正确重定向。我仍然有我的浏览器中显示的重定向地址。那么还有其他想法吗?编辑: 我明显犯了一个错误。上面的代码工作,并做我想要的。它首先没有工作,因为我的重定向网址正在做一些意想不到的事情。
好吧,请你给我一些代码例子吗? – 2010-03-23 08:53:42
在发送HTML代码的维基百科文章(链接到我的文章中的“框架重定向”一词)中有一个很好的例子,但我从来没有写过服务器模块,所以我不知道你会怎么做。也许用'Response.Write(... HTML代码...)'? – 2010-03-23 08:55:51