S
shland
Hi, I'm hoping someone can point me in the right direction. I have a set of
..NET pages on which the user has to login. I also have some .asp pages that
I haven't converted yet. I want to be able to send my user to those .asp
pages without making them log in again (the .asp pages also check for
authorization and make the user log in if no credentials exist.) So, I'd
like to do a POST of the login information when the user clicks on a button
or whatever to go to those .asp pages.
I could put a standard HTML form on the page and allow it to do the post
when the user clicks on a submit button, but then I need to get the login
info from .NET variables to the HTML form input fields. Can I do this, and
is this the best way?
I also have experimented with using HTTPWebRequest object, but so far I
cannot get the browser to stay on the posted URL page (it seems to go the
the URL and then return right back to my .aspx page where I originated the
request). This doesn't happen when I use the HTML form method. Can I
emulate the behavior of the HTML form POST using the HTTPWebRequest object,
or some other variation? If so, where am I going wrong? I'd prefer to
accomplish the job using something of this sort, rather than using an HTML
form, which seems hokey. Here's my experimental code (values are hardcoded
for the purposes of testing): (again I'm a newbie, so be gentle and talk to
me in easy to understand language ;-)
private void btnTest_Click(object sender, System.EventArgs e)
{
string strId = "Admin";
string strPassword = "testpassword";
ASCIIEncoding encoding=new ASCIIEncoding();
string postData="Username="+strId +"&Password="+strPassword;
byte[] data = encoding.GetBytes(postData);
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/test/test.asp");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
newStream.Write(data,0,data.Length);
newStream.Close();
}
Thanks in advance for helping a newbie!
Sheryl
..NET pages on which the user has to login. I also have some .asp pages that
I haven't converted yet. I want to be able to send my user to those .asp
pages without making them log in again (the .asp pages also check for
authorization and make the user log in if no credentials exist.) So, I'd
like to do a POST of the login information when the user clicks on a button
or whatever to go to those .asp pages.
I could put a standard HTML form on the page and allow it to do the post
when the user clicks on a submit button, but then I need to get the login
info from .NET variables to the HTML form input fields. Can I do this, and
is this the best way?
I also have experimented with using HTTPWebRequest object, but so far I
cannot get the browser to stay on the posted URL page (it seems to go the
the URL and then return right back to my .aspx page where I originated the
request). This doesn't happen when I use the HTML form method. Can I
emulate the behavior of the HTML form POST using the HTTPWebRequest object,
or some other variation? If so, where am I going wrong? I'd prefer to
accomplish the job using something of this sort, rather than using an HTML
form, which seems hokey. Here's my experimental code (values are hardcoded
for the purposes of testing): (again I'm a newbie, so be gentle and talk to
me in easy to understand language ;-)
private void btnTest_Click(object sender, System.EventArgs e)
{
string strId = "Admin";
string strPassword = "testpassword";
ASCIIEncoding encoding=new ASCIIEncoding();
string postData="Username="+strId +"&Password="+strPassword;
byte[] data = encoding.GetBytes(postData);
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/test/test.asp");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
newStream.Write(data,0,data.Length);
newStream.Close();
}
Thanks in advance for helping a newbie!
Sheryl