Odd behaviour with webrequest/respone.redirect

M

Mario

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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.
 
J

Joerg Jooss

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...
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Joerg Jooss said:
Thus wrote Ignacio Machin ( .NET/ C# MVP )" ignacio.machin AT
dot.state.fl.us,


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

You are right, I did not see it the first time
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top