jigar1486
jigar1486

Reputation: 33

access ASP.Net Session variable in Facebook C# SDK

I've my ASP.Net HTML 5 Application, Which have the image byte array in Session, I'm using the Latest 5.X C# facebook SDK from CodePlex.

But when user is authorized and Coming back to my canvas page at that time I can't access my ASP.Net Session, its give me a null value.

Here is my Code.

    CanvasAuthorizer _authorizer = new CanvasAuthorizer { Perms = "publish_stream,offline_access,manage_pages" };

    if (!_authorizer.IsAuthorized())
    {

        _authorizer.HttpContext.Session["ImageByte"] = Session["ImageByte"];
        // Go for Login,
        _authorizer.HandleUnauthorizedRequest();
    }
    else
    {
        //After Login
        //Here its give me a null instead of Byte Array(My Image Byte Array).
        byte[] imageByte = (byte[])(_authorizer.HttpContext.Session["ImageByte"]);


        var mediaObject = new FacebookMediaObject
        {
            FileName = "sample.png",
            ContentType = "image/png"
        };


        mediaObject.SetValue(imageByte);

        dynamic parameters = new ExpandoObject();
        parameters.source = mediaObject;

        parameters.uid = _authorizer.Session.UserId;


        var fb = new FacebookClient(Facebook.FacebookContext.Current.AppId, Facebook.FacebookContext.Current.AppSecret);


        parameters.access_token = _authorizer.Session.AccessToken;



        string path = "/me/photos";
        dynamic param = new ExpandoObject();
        param.access_token = _authorizer.Session.AccessToken;
        param.uid = _authorizer.Session.UserId;

        param.source = mediaObject;
        dynamic result = fb.Post(path, param); 

Now pls give me some suggestion, Where I'm missing, How can I access my Application Session. Thanks, Jigar Shah

Upvotes: 0

Views: 1002

Answers (2)

Burak Altinkaya
Burak Altinkaya

Reputation: 21

Try this:

protected void Page_Load(object sender, EventArgs e)
{
    Response.AppendHeader("P3P", "CP=\"CAO PSA OUR\"");

    if (!Page.IsPostBack)
    {

    }
}

Upvotes: 2

niklodeon
niklodeon

Reputation: 1380

I recently found that the following hidden field is required for proper functioning.

Please make shore u have it.

<input type="hidden" name="signed_request" value="<%: Request.Params["signed_request"]%>"/>

Link to my Question

Upvotes: 0

Related Questions