I am trying to implement Single Sign On allowing the users to sign on to multiple vendors. Each vendor has token that need to be send as a form post. I am posting this token as HTTPRequest and getting the Response back like in the code below
private static string PostDataToServerAndGetResponse()
{
Uri uri = new Uri("http://www.amazon.com/exec/obidos/search-handle-form/102-5194535-6807312");
string data = "field-keywords=ASP.NET 2.0";
if (uri.Scheme == Uri.UriSchemeHttp)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Post;
request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded";
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(data);
writer.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string tmp = reader.ReadToEnd();
response.Close();
//return response.ResponseUri.AbsoluteUri;
return tmp;
}
return null;
}
The returned value – tmp is a HTML string which I want to display into an Iframe. I can do this by adding a Literal control in the iframe and setting the text property to the value returned by the above function
<iframe id="myIFrame" runat="server" height="700" width="950" frameborder="0" />
<asp:Literal ID="litFrame" runat="server" Mode="PassThrough" />
</iframe>
litFrame.Text = SAML.PostDataToServerAndGetResponse();
The above code dispaly the page fine, but when i click on any of the links it opens a new page.
There is no apparent framebusting java script, because if I set the ‘src’ attribute of the iframe to response.ResponseUri.AbsoluteUri, all the clicks and page refreshes stay in the frame.
What I want to achieve
Display the Result of the post into Iframe and all the user to perform any clicks.
Condition: Clicks in the frame should refresh the frame and not jump out to a new page.
Iframes do not work they way you think. The content inside an
<iframe>tag is meant to be shown only if the tag is not supported by the browser, not as default content of the iframe. I’m surprised you see any of your literal’s content at all on the page — is there actually an<iframe>output in your html source, or did ASP.NET get ‘smart’ and output something different?Really, your options are:
<form>to the iframe, and post the data to itI’d say option 1 would be the easiest/cleanest.