Click here to Skip to main content
15,907,913 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm Login using Facebook and after successful login i want to redirect user on Home page but it is not redirecting..Please anyone help me out.

Code--
C#
FaceBookConnect.API_Key = "xxxxxxxxxx";
           FaceBookConnect.API_Secret = "xxxxxxxxxxxxxxxxxxxxxxx";



           if (!IsPostBack)
           {
               if (Request.Cookies["email"] != null)
               {
                   txtuser.Text = Request.Cookies["email"].Value;
                   txtpass.Attributes.Add("value", Request.Cookies["pass"].Value);
               }

               //FB Login
               if (Request.QueryString["error"] == "access_denied")
               {
                   ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('User has denied access.')", true);
                   return;
               }

               string code = Request.QueryString["code"];
               if (!string.IsNullOrEmpty(code))
               {
                   string data = FaceBookConnect.Fetch(code, "me");
                   FaceBookUser faceBookUser = new JavaScriptSerializer().Deserialize<FaceBookUser>(data);
                   DataSet chkdata = CommonMethods.SelectData("Select * from Register where email='" + faceBookUser.Email + "'");
                   if (chkdata.Tables[0].Rows.Count == 0)
                   {
                       cmd = new SqlCommand("insert into Register(email,pass,name,contactway,userview,type,cDate) values(@email,@pass,@name,@contactway,@userview,@type,Getdate())", cn);
                       cn.Open();
                       cmd.Parameters.AddWithValue("@email", faceBookUser.Email);
                       cmd.Parameters.AddWithValue("@pass", "Fblogin");
                       cmd.Parameters.AddWithValue("@name", faceBookUser.Name);
                       cmd.Parameters.AddWithValue("@contactway", "Visible Email Address");
                       cmd.Parameters.AddWithValue("@userview", "Yes");
                       cmd.Parameters.AddWithValue("@type", "Private Seller");
                       //cmd.Parameters.AddWithValue("@cdate", DateTime.Now.ToString());
                       cmd.ExecuteNonQuery();
                       cn.Close();
                   }
                   Session["email"] = faceBookUser.Email;
                   Session["username"] = faceBookUser.Name;
                   Label2.Text = faceBookUser.Email;
                   string url = "Main.aspx?email=" + Label2.Text + "";
                   bool a = true;
                   if (a == true)
                   {
                       HttpContext.Current.ApplicationInstance.CompleteRequest();
                       Response.Redirect(url, false);

                       //Response.Write(url);
                   }
               }
           }


I have tried all possible efforts and googled but din get any solution please anyone help me<br />
Thank you
Posted
Comments
Kornfeld Eliyahu Peter 29-Sep-14 9:38am    
1. debug to see if you get to the line
2. try Response.Redirect(url);
Surendra0x2 29-Sep-14 9:40am    
when i placed my code inside try catch block i got error Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
thats y i added Response.Redirect(url, false); false but it did not work.
Richard Deeming 29-Sep-14 9:51am    
Your code is susceptible to SQL Injection[^]:
CommonMethods.SelectData("Select * from Register where email='" + faceBookUser.Email + "'");

Also, try moving the HttpContext.Current.ApplicationInstance.CompleteRequest call after the Response.Redirect call.
Surendra0x2 29-Sep-14 10:04am    
sir yes it is vulnerable to sql injection but i ll do this using Stored procedure but i want to resolve my current issue i added HttpContext.Current.ApplicationInstance.CompleteRequest after response.redirect but still unable to redirect :(
Sreekanth Mothukuru 30-Sep-14 8:05am    
I think you need to set the return URL while registering your app at Facebook using your developer account. Check to see if you might have missed the return URL field there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900