Please Help: Posting and redirecting to another form.

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi Denise,

I suppose the key point is to put Response content from
php page (HttpWebResponse) into Response of your page
(this.Response)

You can try following code

//>>>>... how to do I send the user to the page that
follows...?

// Get stream of php page Response
System.IO.BinaryReader phpStream = new BinaryReader
(response.GetResponseStream());
// prepare an byte array for php page content
byte[] phpBytes = new bytes[phpStream.Length];
// get the content
phpStream.Read(phpBytes, 0, phpStream.Length);
phpStream.Close();
// clear current page
this.Response.Clear();
// write php page content to current page
this.Response.BinaryWrite(phpBytes);
// Sends all currently buffered output to the client,
stops execution of the page
this.Response.End();


HTH

Elton Wang
elton_wang@xxxxxxxxxxx


>-----Original Message-----
>I have posted a similar message in 2 other forums but got
no response. I
>have spent more hours than I can count researching this.
Can anyone provide
>some insight...?
>
>Our ASP.Net application needs to transparently log a user
on to a separate
>secure web site (PHP - not controlled by us). We want
to save the user the
>step of typing in his username and password and having to
press submit.
>
>I could accomplish this by using the <form
action="myform.php"
>method="post"> but I would have to store the password in
a hidden field that
>could be easily viewed.
>
>I thought I was on the right track with the below code...
but I cannot
>figure out how to actually redirect the user to the page
that appears after
>login. (Response.redirect only shows the login page
again, even though I
>just posted the login values.)
>
>HttpWebRequest request = (HttpWebRequest)
>WebRequest.Create("https://myServer/myPage.php";);
>request.Method = "POST";
>request.ContentType = "application/x-www-form-urlencoded";
>request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1)";
>request.KeepAlive = true;
>request.AllowAutoRedirect = true;
>request.ContentType ="application/x-www-form-urlencoded";
>
>string body
= "logOnUserName=mek&userPwd=mypass&Submit=submit";
>byte[] bytes = Encoding.ASCII.GetBytes(body);
>request.ContentLength = bytes.Length;
>
>StreamWriter stOut = new StreamWriter
(request.GetRequestStream(),
>System.Text.Encoding.ASCII);
>stOut.Write(body);
>stOut.Close();
>HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
>>>>>... how to do I send the user to the page that
follows...?
>
>I have also tried code presented on this forum (below),
but this only brings
>the information into my page, it does not post the
username and password and
>redirect:
>
>private void DoPost()
>{
>String uriString ="https://myServer/myPage.php?";;
>System.Net.WebClient myWebClient = new
System.Net.WebClient();
>System.Collections.Specialized.NameValueCollection
>System.Collections.Specialized.NameValueCollection
myNameValueCollection =
>new System.Collections.Specialized.NameValueCollection();
>
>myNameValueCollection.Add("logOnUserName", "me");
>myNameValueCollection.Add("userPwd", "mypass");
>myNameValueCollection.Add("OrganizationId", "1234");
>myNameValueCollection.Add("Submit", "");
>
>myWebClient.UploadValues (uriString, "POST",
myNameValueCollection)
>Byte[] responseArray = myWebClient.UploadValues
(uriString, "POST",
>myNameValueCollection);
>
>Label1.Text = "Response received was : " +
>System.Text.Encoding.ASCII.GetString(responseArray);
>}
>
>Any suggestions would be greatly appreciated!
>.
>
.



Relevant Pages

  • RE: Please Help: Posting and redirecting to another form.
    ... > I suppose the key point is to put Response content from ... > // Get stream of php page Response ... (Response.redirect only shows the login page ... >>StreamWriter stOut = new StreamWriter ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Post with redirect?
    ... How can I force a POST but actually redirect the user as well ... and it can't be done with PHP. ... return $response; ... its a credit card entry form on a completely separate server. ...
    (comp.lang.php)
  • Randomly request timeout (IIS6.0)
    ... I have got IIS 6.0 on Windows 2003 Server. ... string host_address ... HttpWebResponse response; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: dynamic button not working
    ... Thank you for such an informative and complete response. ... You actually led me to the real problem and, yes, it is PHP related. ... Is there something I can do in my PHP script prior to returning the HTML string that will strip those slashes? ... unless you run some code over the response string by accident. ...
    (comp.lang.php)
  • Re: Accessing cookies returned in error responses with httpwebrequest (.net CF)
    ... > authentication using the NetworkCredential class, ... > The problem is that the site uses cookies to track the user attempting ... > reinserting them manually (using the Headers property of the response ... > HttpWebResponse object to poach them from. ...
    (microsoft.public.dotnet.framework)