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