Frame Redirect in C#
I would like to execute a frame redirect in C# from my managed module for the IIS 7.
When I callcontext.Response.Redirect(@"http://www.myRedirect.org");
the correct 开发者_JAVA技巧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.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
精彩评论