Array Index out of Bounds while doing FaceBook Login in a Web Forms Application --- RRS feed

  • Question

  • Hello All,

    I have a certain coding difficulty. It's regarding the implementation of FaceBook Login in an asp.net web forms application. I did more or less most of the things. Just a certain error remaining & it's got more to do with the array index concepts.

    The page where the application will be redirected and some information will be shown reg. who logged in with FB credentials is named Dashboard.aspx.
    There, in the code behind, I did ::

    protected void Page_Load(object sender, EventArgs e)
                if (Request.QueryString["code"] != "")
                    var obj = GetFacebookUserData(Request.QueryString["code"]);
                    lggdNM.InnerText = obj[1].ToString();
                    locnNM.InnerText= obj[7].ToString();

    where ''GetFacebookUserData(string code)'' is the method I wrote inside which I did the work with AppId, AppSecret, Tokens and other parameters to read a stream of the data for the user who logged in with FB.

    Also, my template class is FBUser.cs :::

    public class FBUser
            public string id { get; set; }
            public string first_name { get; set; }
            public string last_name { get; set; }
            public string link { get; set; }
            public string username { get; set; }
            public string gender { get; set; }
            public string locale { get; set; }

    which you can understand has the different properties.

    The only error I am getting is this :::

    Index was out of range. Must be non negative and less than the size of the collection. Parameter name: Index.
    on these lines ::
    lggdNM.InnerText = obj[1].ToString()+" "+obj[2].ToString();
    locnNM.InnerText= obj[7].ToString();
    these are just two labels where I intended to show the name of the user and his locale. Hence I tried to use the index of the resp. property from my model class.

    This is the error. That's all. Why it's saying that index is out of bounds, I'm a little worried. The FBUser class properties, it is definitely a zero based index. So what wrong code I wrote, please help me a little friends.

    Thanks a lot.
    Merry Christmas All!!       : )

    • Moved by CoolDadTx Tuesday, December 22, 2015 5:35 PM Wrong forums
    Tuesday, December 22, 2015 5:18 PM