我想在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