By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,084 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,084 IT Pros & Developers. It's quick & easy.

Please Help: Posting and redirecting to another form.

P: n/a
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=submi t";
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!
Nov 19 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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
el********@hotmail.com

-----Original Message-----
I have posted a similar message in 2 other forums but got no response. Ihave spent more hours than I can count researching this. Can anyone providesome insight...?

Our ASP.Net application needs to transparently log a user on to a separatesecure web site (PHP - not controlled by us). We want to save the user thestep 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 thatcould be easily viewed.

I thought I was on the right track with the below code... but I cannotfigure out how to actually redirect the user to the page that appears afterlogin. (Response.redirect only shows the login page again, even though Ijust 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=submi t";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 bringsthe information into my page, it does not post the username and password andredirect:

private void DoPost()
{
String uriString ="https://myServer/myPage.php?";
System.Net.WebClient myWebClient = new System.Net.WebClient();System.Collections.Specialized.NameValueCollectio n
System.Collections.Specialized.NameValueCollectio n 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(responseArra y);
}

Any suggestions would be greatly appreciated!
.

Nov 19 '05 #2

P: n/a
Elton,

Thanks for your reply. I am trying to implement your suggestions, but I get
compile errors on "phpStream.Length", 'System.IO.BinaryReader' does not
contain a definition for 'Length'. I don't know enough about binary readers
to fix this. Do I need an interim step?

Denise


"Elton Wang" wrote:
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
el********@hotmail.com

-----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=submi t";
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.NameValueCollectio n
System.Collections.Specialized.NameValueCollectio n

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(responseArra y);
}

Any suggestions would be greatly appreciated!
.

Nov 19 '05 #3

P: n/a
Elton,

Thanks for your reply. I am trying to implement your suggestions, but I get
compile errors on "phpStream.Length", 'System.IO.BinaryReader' does not
contain a definition for 'Length'. I don't know enough about binary readers
to fix this. Do I need an interim step?

Denise


"Elton Wang" wrote:
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
el********@hotmail.com

-----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=submi t";
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.NameValueCollectio n
System.Collections.Specialized.NameValueCollectio n

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(responseArra y);
}

Any suggestions would be greatly appreciated!
.

Nov 19 '05 #4

P: n/a
Hi Denise,

You can change BinaryReader to BufferedStream. The
BufferedStream class has Length property and can also
perform Read operation.

I am still thinking your goal. Actually my code only
present content that HttpWebRequest object gets from its
request page. Hence suppose your HttpWebRequest object
successfully log in request page, it doesn't redirect to
that page. Instead it shows contents of the page. It's not
what you exactly want.

Redirect direct from server (Response.Redirect(url))
doesn't help at all. Because it's Request object doesn't
provide actual content, such as userID, password,
although they are in Request object.

I was just wondering why don't you let user log in
directly to that site?

HTH

Elton
-----Original Message-----
Elton,

Thanks for your reply. I am trying to implement your suggestions, but I getcompile errors on "phpStream.Length", 'System.IO.BinaryReader' does notcontain a definition for 'Length'. I don't know enough about binary readersto fix this. Do I need an interim step?

Denise


"Elton Wang" wrote:
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
el********@hotmail.com

>-----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=submi t";
>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.NameValueCollectio n
>System.Collections.Specialized.NameValueCollectio n

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(responseArra y);
>}
>
>Any suggestions would be greatly appreciated!
>.
>

.

Nov 19 '05 #5

P: n/a
It is a requirement of our application. When the user logs into the parent
site, the client wants their users to be able to access the affiliated site
without having to remember another login.. a convenience for their users. We
have access to all the information about their login.

On this project, I am the developer, not the designer. Someone sold this
idea to the client - I have to make it happen. Is there ANYTHING else you
can think of...???

Denise

"Elton Wang" wrote:
Hi Denise,

You can change BinaryReader to BufferedStream. The
BufferedStream class has Length property and can also
perform Read operation.

I am still thinking your goal. Actually my code only
present content that HttpWebRequest object gets from its
request page. Hence suppose your HttpWebRequest object
successfully log in request page, it doesn't redirect to
that page. Instead it shows contents of the page. It's not
what you exactly want.

Redirect direct from server (Response.Redirect(url))
doesn't help at all. Because it's Request object doesn't
provide actual content, such as userID, password,
although they are in Request object.

I was just wondering why don't you let user log in
directly to that site?

HTH

Elton
-----Original Message-----
Elton,

Thanks for your reply. I am trying to implement your

suggestions, but I get
compile errors

on "phpStream.Length", 'System.IO.BinaryReader' does not
contain a definition for 'Length'. I don't know enough

about binary readers
to fix this. Do I need an interim step?

Denise


"Elton Wang" wrote:
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
el********@hotmail.com
>-----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=submi t";
>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.NameValueCollectio n
>System.Collections.Specialized.NameValueCollectio n
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(responseArra y);
>}
>
>Any suggestions would be greatly appreciated!
>.
>

.

Nov 19 '05 #6

P: n/a
So in your page, you only track user log info then
redirect to target page that's it. Or you need also to
track if log on successful or failure?

Elton

-----Original Message-----
It is a requirement of our application. When the user logs into the parentsite, the client wants their users to be able to access the affiliated sitewithout having to remember another login.. a convenience for their users. Wehave access to all the information about their login.

On this project, I am the developer, not the designer. Someone sold thisidea to the client - I have to make it happen. Is there ANYTHING else youcan think of...???

Denise

"Elton Wang" wrote:
Hi Denise,

You can change BinaryReader to BufferedStream. The
BufferedStream class has Length property and can also
perform Read operation.

I am still thinking your goal. Actually my code only
present content that HttpWebRequest object gets from its
request page. Hence suppose your HttpWebRequest object
successfully log in request page, it doesn't redirect to that page. Instead it shows contents of the page. It's not what you exactly want.

Redirect direct from server (Response.Redirect(url))
doesn't help at all. Because it's Request object doesn't provide actual content, such as userID, password,
although they are in Request object.

I was just wondering why don't you let user log in
directly to that site?

HTH

Elton
>-----Original Message-----
>Elton,
>
>Thanks for your reply. I am trying to implement your

suggestions, but I get
>compile errors

on "phpStream.Length", 'System.IO.BinaryReader' does not
>contain a definition for 'Length'. I don't know enough about binary readers
>to fix this. Do I need an interim step?
>
>Denise
>
>
>
>
>"Elton Wang" wrote:
>
>> 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
>> el********@hotmail.com
>>
>>
>> >-----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=submi t";
>> >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.NameValueCollectio n
>> >System.Collections.Specialized.NameValueCollectio n
>> 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(responseArra y);
>> >}
>> >
>> >Any suggestions would be greatly appreciated!
>> >.
>> >
>>
>.
>

.

Nov 19 '05 #7

P: n/a
I would be happy just to redirect them. If I can determine if the logon was
sucessful, that would be great, but not absolutely necesssary.

Denise

"Elton Wang" wrote:
So in your page, you only track user log info then
redirect to target page that's it. Or you need also to
track if log on successful or failure?

Elton

-----Original Message-----
It is a requirement of our application. When the user

logs into the parent
site, the client wants their users to be able to access

the affiliated site
without having to remember another login.. a convenience

for their users. We
have access to all the information about their login.

On this project, I am the developer, not the designer.

Someone sold this
idea to the client - I have to make it happen. Is there

ANYTHING else you
can think of...???

Denise

"Elton Wang" wrote:
Hi Denise,

You can change BinaryReader to BufferedStream. The
BufferedStream class has Length property and can also
perform Read operation.

I am still thinking your goal. Actually my code only
present content that HttpWebRequest object gets from its request page. Hence suppose your HttpWebRequest object
successfully log in request page, it doesn't redirect to that page. Instead it shows contents of the page. It's not what you exactly want.

Redirect direct from server (Response.Redirect(url))
doesn't help at all. Because it's Request object doesn't provide actual content, such as userID, password,
although they are in Request object.

I was just wondering why don't you let user log in
directly to that site?

HTH

Elton
>-----Original Message-----
>Elton,
>
>Thanks for your reply. I am trying to implement your
suggestions, but I get
>compile errors
on "phpStream.Length", 'System.IO.BinaryReader' does not >contain a definition for 'Length'. I don't know enough about binary readers
>to fix this. Do I need an interim step?
>
>Denise
>
>
>
>
>"Elton Wang" wrote:
>
>> 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
>> el********@hotmail.com
>>
>>
>> >-----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=submi t";
>> >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.NameValueCollectio n
>> >System.Collections.Specialized.NameValueCollectio n
>> 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(responseArra y);
>> >}
>> >
>> >Any suggestions would be greatly appreciated!
>> >.
>> >
>>
>.
>

.

Nov 19 '05 #8

P: n/a
I have an idea. It lets page to rebound to client first.
Then on client-side, change the form's request URL to
target URL, and automatically submit. You can try this
idea by following method:

private void Rebound(string Url)
{
string txtPw = this.txtPw.Text;
string PWclientID = this.txtPw.ClientID;
string txtUser = this.txtUser.Text;
string UserclientID = this.txtUser.ClientID;
string scriptString = "<script
language=JavaScript> ";
scriptString += "var theform;";
scriptString += "if
(window.navigator.appName.toLowerCase().indexOf
(\"microsoft\") > -1) {";
scriptString += "theform = document.Form1;";
scriptString += "}else {";
scriptString += "theform = document.forms[\"Form1
\"];";
scriptString += "}theform.action =\"" + Url
+ "\";";
scriptString += "theform." + PWclientID
+ ".value='" + txtPw + "';";
scriptString += "theform." + UserclientID
+ ".value='" + txtUser + "';";
scriptString += "theform.submit();";
scriptString += "</script>";
RegisterStartupScript("clientScript",
scriptString);
}

HTH

Elton
-----Original Message-----
I would be happy just to redirect them. If I can determine if the logon wassucessful, that would be great, but not absolutely necesssary.
Denise

"Elton Wang" wrote:
So in your page, you only track user log info then
redirect to target page that's it. Or you need also to
track if log on successful or failure?

Elton

>-----Original Message-----
>It is a requirement of our application. When the user

logs into the parent
>site, the client wants their users to be able to access
the affiliated site
>without having to remember another login.. a
convenience
for their users. We
>have access to all the information about their login.
>
>On this project, I am the developer, not the
designer. Someone sold this
>idea to the client - I have to make it happen. Is
there ANYTHING else you
>can think of...???
>
>Denise
>
>"Elton Wang" wrote:
>
>> Hi Denise,
>>
>> You can change BinaryReader to BufferedStream. The
>> BufferedStream class has Length property and can
also >> perform Read operation.
>>
>> I am still thinking your goal. Actually my code only
>> present content that HttpWebRequest object gets from

its
>> request page. Hence suppose your HttpWebRequest object >> successfully log in request page, it doesn't redirect to
>> that page. Instead it shows contents of the page.
It's not
>> what you exactly want.
>>
>> Redirect direct from server (Response.Redirect(url))
>> doesn't help at all. Because it's Request object

doesn't
>> provide actual content, such as userID, password,
>> although they are in Request object.
>>
>> I was just wondering why don't you let user log in
>> directly to that site?
>>
>> HTH
>>
>> Elton
>> >-----Original Message-----
>> >Elton,
>> >
>> >Thanks for your reply. I am trying to implement
your >> suggestions, but I get
>> >compile errors
>> on "phpStream.Length", 'System.IO.BinaryReader' does not
>> >contain a definition for 'Length'. I don't know

enough
>> about binary readers
>> >to fix this. Do I need an interim step?
>> >
>> >Denise
>> >
>> >
>> >
>> >
>> >"Elton Wang" wrote:
>> >
>> >> 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
>> >> el********@hotmail.com
>> >>
>> >>
>> >> >-----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=submi t"; >> >> >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.NameValueCollectio n >> >>System.Collections.Specialized.NameValueCollectio n >> >> 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!
>> >> >.
>> >> >
>> >>
>> >.
>> >
>>
>.
>

.

Nov 19 '05 #9

P: n/a
Elton,

I tried this solution and it does work. My only concern is that if a user
navigates back to this window and does a viewsource, the password will
be visible in the javascript code... but the page was dynamically created on
his machine so chances of security problems would be minimized.

I still wish I could get the redirect from the server side working after the
post ... but this may have to do. Thank so much for your great ideas.

Denise

"Elton Wang" wrote:
I have an idea. It lets page to rebound to client first.
Then on client-side, change the form's request URL to
target URL, and automatically submit. You can try this
idea by following method:

private void Rebound(string Url)
{
string txtPw = this.txtPw.Text;
string PWclientID = this.txtPw.ClientID;
string txtUser = this.txtUser.Text;
string UserclientID = this.txtUser.ClientID;
string scriptString = "<script
language=JavaScript> ";
scriptString += "var theform;";
scriptString += "if
(window.navigator.appName.toLowerCase().indexOf
(\"microsoft\") > -1) {";
scriptString += "theform = document.Form1;";
scriptString += "}else {";
scriptString += "theform = document.forms[\"Form1
\"];";
scriptString += "}theform.action =\"" + Url
+ "\";";
scriptString += "theform." + PWclientID
+ ".value='" + txtPw + "';";
scriptString += "theform." + UserclientID
+ ".value='" + txtUser + "';";
scriptString += "theform.submit();";
scriptString += "</script>";
RegisterStartupScript("clientScript",
scriptString);
}

HTH

Elton
-----Original Message-----
I would be happy just to redirect them. If I can

determine if the logon was
sucessful, that would be great, but not absolutely

necesssary.

Denise

"Elton Wang" wrote:
So in your page, you only track user log info then
redirect to target page that's it. Or you need also to
track if log on successful or failure?

Elton
>-----Original Message-----
>It is a requirement of our application. When the user
logs into the parent
>site, the client wants their users to be able to access the affiliated site
>without having to remember another login.. a convenience for their users. We
>have access to all the information about their login.
>
>On this project, I am the developer, not the designer. Someone sold this
>idea to the client - I have to make it happen. Is there ANYTHING else you
>can think of...???
>
>Denise
>
>"Elton Wang" wrote:
>
>> Hi Denise,
>>
>> You can change BinaryReader to BufferedStream. The
>> BufferedStream class has Length property and can also >> perform Read operation.
>>
>> I am still thinking your goal. Actually my code only
>> present content that HttpWebRequest object gets from
its
>> request page. Hence suppose your HttpWebRequest object >> successfully log in request page, it doesn't redirect to
>> that page. Instead it shows contents of the page. It's not
>> what you exactly want.
>>
>> Redirect direct from server (Response.Redirect(url))
>> doesn't help at all. Because it's Request object
doesn't
>> provide actual content, such as userID, password,
>> although they are in Request object.
>>
>> I was just wondering why don't you let user log in
>> directly to that site?
>>
>> HTH
>>
>> Elton
>> >-----Original Message-----
>> >Elton,
>> >
>> >Thanks for your reply. I am trying to implement your >> suggestions, but I get
>> >compile errors
>> on "phpStream.Length", 'System.IO.BinaryReader' does not
>> >contain a definition for 'Length'. I don't know
enough
>> about binary readers
>> >to fix this. Do I need an interim step?
>> >
>> >Denise
>> >
>> >
>> >
>> >
>> >"Elton Wang" wrote:
>> >
>> >> 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
>> >> el********@hotmail.com
>> >>
>> >>
>> >> >-----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=submi t"; >> >> >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.NameValueCollectio n
>> >>

System.Collections.Specialized.NameValueCollectio n
>> >> 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!
>> >> >.
>> >> >
>> >>
>> >.
>> >
>>
>.
>

.

Nov 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.