471,319 Members | 1,430 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

Odd behaviour with webrequest/respone.redirect

Greetings!

Here is the problem i'm facing. I'm supposed to read some user input on
Page1, then, depends on what the user inputs, redirect him to Page2 or
Page3 and send the entered data with it. Page2 or Page3 will then do
some user verification and depending on success/failure redirect again
to Page1(failure) or Page4(success)

So far i managed to implement sending the data with webrequest, but the
problem comes with redirection.
Code on Page1:

request = WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
builder = new StringBuilder();
builder.Append(HttpUtility.UrlEncode("UserID"));
builder.Append("=");
builder.Append(HttpUtility.UrlEncode(userid));
builder.Append("&");
builder.Append(HttpUtility.UrlEncode("Password"));
builder.Append("=");
builder.Append(HttpUtility.UrlEncode(password));

bytes = Encoding.UTF8.GetBytes(builder.ToString());
request.ContentLength = bytes.Length;
stream = request.GetRequestStream();
stream.Write(bytes, 0, bytes.Length);
stream.Close();
Response.Redirect("Page2 or Page3");
Here is the code on Page2/Page3:

userid=Request["userid"];
password=Request["password"];

if (Session.IsNewSession)
{
Session.Add("Login", false);
Session.Add("userid", "");
Session.Add("pword", "");
}

if ((userid!=null)&&(password!=null)&&(userid!="")&&( password!=""))
{
if (TryLogin(userid, password))
{

Session["userid"]=userid;
Session["pword"]=password;

uname.Text=Session["userid"].ToString();
pword.Text=Session["pword"].ToString();
Session["Login"]=true;
}
else
{
uname.Text=userid;
pword.Text=password;
Session["Login"]=false;
}
if ((bool)Session["Login"])
Response.Redirect("http://Page4");
else
{
Response.Redirect("http://Page1");
}
}

uname and pword are textbox fields on the form. The problem is that
their values do not change on the form and response.redirect doesnt
work neither...

if i remove response.redirect from page1 than it works, but i need the
browser to redirect the user. is there some other way i could do this?

Any help appreciated!
Thank You

Feb 24 '06 #1
3 4951
Hi

Is this a win app?

I'm kind of lost, cause you are talking about server side functionality but
your code looks like client side.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Mario" <ma*****@hotmail.com> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
Greetings!

Here is the problem i'm facing. I'm supposed to read some user input on
Page1, then, depends on what the user inputs, redirect him to Page2 or
Page3 and send the entered data with it. Page2 or Page3 will then do
some user verification and depending on success/failure redirect again
to Page1(failure) or Page4(success)

So far i managed to implement sending the data with webrequest, but the
problem comes with redirection.
Code on Page1:

request = WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
builder = new StringBuilder();
builder.Append(HttpUtility.UrlEncode("UserID"));
builder.Append("=");
builder.Append(HttpUtility.UrlEncode(userid));
builder.Append("&");
builder.Append(HttpUtility.UrlEncode("Password"));
builder.Append("=");
builder.Append(HttpUtility.UrlEncode(password));

bytes = Encoding.UTF8.GetBytes(builder.ToString());
request.ContentLength = bytes.Length;
stream = request.GetRequestStream();
stream.Write(bytes, 0, bytes.Length);
stream.Close();
Response.Redirect("Page2 or Page3");
Here is the code on Page2/Page3:

userid=Request["userid"];
password=Request["password"];

if (Session.IsNewSession)
{
Session.Add("Login", false);
Session.Add("userid", "");
Session.Add("pword", "");
}

if ((userid!=null)&&(password!=null)&&(userid!="")&&( password!=""))
{
if (TryLogin(userid, password))
{

Session["userid"]=userid;
Session["pword"]=password;

uname.Text=Session["userid"].ToString();
pword.Text=Session["pword"].ToString();
Session["Login"]=true;
}
else
{
uname.Text=userid;
pword.Text=password;
Session["Login"]=false;
}
if ((bool)Session["Login"])
Response.Redirect("http://Page4");
else
{
Response.Redirect("http://Page1");
}
}

uname and pword are textbox fields on the form. The problem is that
their values do not change on the form and response.redirect doesnt
work neither...

if i remove response.redirect from page1 than it works, but i need the
browser to redirect the user. is there some other way i could do this?

Any help appreciated!
Thank You

Feb 24 '06 #2
Thus wrote Ignacio Machin ( .NET/ C# MVP )" ignacio.machin AT dot.state.fl.us,
Hi

Is this a win app?

I'm kind of lost, cause you are talking about server side
functionality but your code looks like client side.


And it looks a lot like a reimplementation of Forms Authentication...

--
Joerg Jooss
ne********@joergjooss.de
Feb 24 '06 #3
Hi,
"Joerg Jooss" <ne********@joergjooss.de> wrote in message
news:94**************************@msnews.microsoft .com...
Thus wrote Ignacio Machin ( .NET/ C# MVP )" ignacio.machin AT
dot.state.fl.us,
Hi

Is this a win app?

I'm kind of lost, cause you are talking about server side
functionality but your code looks like client side.


And it looks a lot like a reimplementation of Forms Authentication...


You are right, I did not see it the first time
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Feb 24 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Antonio | last post: by
reply views Thread by vMike | last post: by
12 posts views Thread by ThyRock | last post: by
reply views Thread by theintrepidfox | last post: by
3 posts views Thread by guoqi zheng | last post: by
8 posts views Thread by Dox33 | last post: by
2 posts views Thread by =?Utf-8?B?R1ROMTcwNzc3?= | last post: by
8 posts views Thread by =?Utf-8?B?cm9kY2hhcg==?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.