Mubashar Sajjad
Mubashar Sajjad

Reputation: 31

page does not redirected using HttpContext.Current.Server.Transfer("transferedPageName.aspx")

I am trying to authenticate my users using their facebook ids. For that I have their facebook id. saved in my database at the time of registration. I am using javascript API of facebook for that and it is working fine brings back user to my site with the user basci information where from .aspx page on success i am using jQuery ajax call

FB.Event.subscribe('auth.statusChange', function (response) {
if (response.authResponse) {                                                                                       FB.api('/me?email?dob', function (me) {                                                   if (me.name) {                                                       
   emid = me.email;
   $.ajax({
           url: 'index.aspx/checkuser',
           type: 'POST',
           contentType: 'application/json',
           data: JSON.stringify({ eid: emid }),
}
})
});

the above code is on my masterpage.aspx to a webMethod in my code behind which is a static method

[WebMethod]
    public static void checkuser(string eid)
    {
        checkFBDB objChk = new checkFBDB();
        objChk.isFBIDExists(eid);


    }

this code is on the content page index.aspx and within that method i am calling a class function by creating class object public class checkFBDB : System.Web.UI.Page {

    public void isFBIDExists(string fbID)
    {

        string cnString = string.Empty;

        cnString = ConfigurationManager.ConnectionStrings["connectionString"].ToString();

            SqlDataReader dR = SqlHelper.ExecuteReader(cnString,
         CommandType.Text, "SELECT * FROM smsUsers WHERE fbA='" + fbID + "' ");

            if (dR.Read())
            {

                Session["userName"] = dR["userName"].ToString();
                Session["smsCredit"] = int.Parse(dR["SMSCredit"].ToString());
                Session["sender"] = dR["FName"].ToString();
                Session["userMob"] = dR["MobileNo"].ToString();
                HttpContext.Current.Server.Transfer("AuthenticatedForms/sendMessage.aspx");

            }

            else
            {
                HttpContext.Current.Server.Transfer("~/mapFBID.aspx",true);
            }
       }
}

which opens connections with the database and verifies if the user exists in our DB with the provided facebook id then "HttpContext.Current.Server.Transfer("AuthenticatedForms/sendMessage.aspx");" i am using this statement but the problem is if i use the same statement from a nomral page it transfers fine but from this code class it transfers performs all operations i have seen in debug mode but comes back to the page from where web method has been called which is calling this code class for the transfering of control. I am using master pages. Visual Studio 2010, back end is SQL SERVER 2000. Following is my Code. Thank You in advance for any assistance.

Upvotes: 1

Views: 1684

Answers (1)

Ramesh
Ramesh

Reputation: 13266

There are few things which you need to consider.

  1. You are making an AJAX call and on success you want the use to be redirected to a page.
  2. Server.Transfer does write the content of the target page in the response stream and this would not help us to take the user to different page especially during AJAX call.
  3. You can perform Response.Redirect but, even that case wouldn't work as the AJAX logic is completely ignorant of understanding the 302 response.

I would recommend to follow SO Question "How to manage a redirect request after a jQuery Ajax call"

Upvotes: 1

Related Questions