簡體   English   中英

從iframe內部重定向到頁面

[英]redirecting to page from inside iframe

我剛剛開始在.NET框架中編寫代碼,所以如果這個問題恰好是微不足道的話我會道歉。

我現在得到了什么

一個main.aspx頁面,使用三個iframe進行簡單布局

在此輸入圖像描述

中間的iframe內容需要是動態的(首先是login.aspx頁面並且在記錄entryform.aspx


問題#1

在iframe中登錄login.aspx后,重定向到main.aspx

我發現的解決方案

ClientScript.RegisterStartupScript(this.GetType(),"scriptid", "window.parent.location.href='main.aspx'", true);

http://forums.asp.net/t/1273497.aspx


問題#2

重定向/記錄后如何將中間iframe內容從login.aspx更改為entryform.aspx

我想到的愚蠢的解決方案

“#form”添加到url並在main.aspx中偵聽hashchange事件。 但是,任何人都可以使用url本身訪問表單。


那么,基本上我如何找到一種安全的方式來告訴main.aspx頁面,它需要在重定向/記錄后更改它的中間iframe內容

或者有任何機會在.NET中有一個request.setAttribute和getAttribute ,就像我錯過了java並讓我感到困難一樣?

在頁面和域之間傳遞變量或值不會有問題,您可以使用post方法和跨頁面發布

在發現iframe的使用並不是我最好的想法之后,我接受了Tieson T的建議並調查了HttpClient以從其他網頁獲取內容。 在我的情況下,它將來自同一域和其他域。

由於我使用的是4.0v .NET而不是HttpClient,因此我使用了HttpWebRequest

HttpWebRequest request = (HttpWebRequest)WebRequest.Create (http://localhost:1706/WebSite3/test.html);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
StreamReader reader = new StreamReader(response.GetResponseStream(),encode );
string html= reader.ReadToEnd();
myDiv.innerHtml(html);

參考

將參數傳遞給Main.aspx會不會更容易? 例如

ClientScript.RegisterStartupScript(this.GetType(),"scriptid", "window.parent.location.href='main.aspx?LoadEntry=true'", true);

'main.aspx'中的客戶端JavaScript代碼將從'location.search'讀取該參數,如果設置了'LoadEntry = true',則將中間幀的SRC設置為“entryform.aspx”。

當然在“entryform.aspx.cs”中,您需要檢查是否確實發生了正確的登錄(例如,設置了一些Session變量),因此沒有人能夠簡單地將URL手動設置為“main.aspx?LoadEntry = true”繞過登錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM