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! 9 1787
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! .
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. 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! .
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. 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! .
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! >. > .
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 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! >. > .
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! >> >. >> > >> >. > .
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 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! >> >. >> > >> >. > .
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! >> >> >. >> >> > >> >> >> >. >> > >> >. > .
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 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! >> >> >. >> >> > >> >> >> >. >> > >> >. > .
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Don Seckler |
last post by:
I am trying to set up a PHP web page so I can enter data into a
database.
I created a form:
<form action="admin_news_insert_processor.php" method="post"
name="frm_Insert_News"...
|
by: Jack Schitt |
last post by:
I thought I was starting to get a handle on Access, until I tried
doing something useful...now I'm stuck. I have a DB with two tables -
to keep it simple I'll say that one is an Employee File...
|
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application...
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej...
|
by: Dynamo |
last post by:
Firstly, many thanks to those who replied to my dreaded what if question. As a
result I have now been able to partially resolve my problem as follows:
step 1 - User clicks on "buy me" button
step...
|
by: rasiel |
last post by:
I'm hoping someone can help me out. I'm a researcher in need of
developing an automated database and would like to see if someone here
is willing to consider putting together for me a simple...
|
by: slavisa |
last post by:
Hi, i have a form and i use cgi script to email the results back to me.
I have a javascript in there already that checks if the required fields are filled when you click submit and if they are not...
|
by: SirG |
last post by:
I'm looking for an explanation of why one piece of code works and
another does not. I have to warn you that this is the first piece of
Javascript I've ever written, so if there is a better way or a...
|
by: Jonathan Wood |
last post by:
I've spent days trying to come up with a solution. I'd appreciate it if
anyone can help.
My site requires all users to log on. There are three different roles of
users, and each user type will...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |