Facebook Channel File in ASP.NET

according to the facebook Javascript SDK, the facebook application should include a “channel file” in their initialization code. as published here: http://developers.facebook.com/docs/reference/javascript/

I did not completely understand why they needed it, or what should be the contents of this file, but I just use their main example, as this can help in some specific problems.

my question is - they said that this channel.html file should be cached. and even gave an example of how to cache it using PHP:

<?php $cache_expire = 60*60*24*365; header("Pragma: public"); header("Cache-Control: max-age=".$cache_expire); header('Expires: ' . gmdate('D, d MYH:i:s', time()+$cache_expire) . ' GMT'); ?> 

the thing is AFAIK, which cannot be executed with asp.net, since I cannot put C # code in an html file.

so meanwhile I just add it hard, for example:

 <head> <meta http-equiv="cache-control" content="max-age=31536000;public" /> <meta http-equiv="expires" content="31536000" /> </head> 

im not sure if this is the right way to do this, since "expires" should be specified on a specific format date.

any ideas how i can do it right? maybe i can use facebook 'channel.aspx' instead?

+4
source share
2 answers

Here's how you do it in asp.net for this one:

  • Create a shared HTTP handler (ashx file):

     public class FacebookChannel : IHttpHandler { public void ProcessRequest(HttpContext context) { HttpResponse response = context.Response; response.ClearHeaders(); const int cacheExpires = 60 * 60 * 24 * 365; response.AppendHeader("Pragma", "public"); response.AppendHeader("Cache-Control", "max-age=" + cacheExpires); response.AppendHeader("Expires", DateTime.Now.ToUniversalTime().AddSeconds(cacheExpires).ToString("r")); context.Response.ContentType = "text/html"; context.Response.Write("<script src=\"//connect.facebook.net/en_US/all.js\"></script>"); } public bool IsReusable { get { return false; } } } 

Make sure you link to the URL in your FB.init function :

channelUrl: '//WWW.YOUR_DOMAIN.COM/fbchannel.ashx',

+5
source

the channel file is optional, but recommended, the channel file is used to solve some cross-connection problems (from your domain to facebook.com) in some browsers, you can use channel.aspx if it returns the contents described by the API. Channel file caching is recommended for web applications, read this to find out how asp.net handles caching: http://msdn.microsoft.com/enus/library/xsbfdd8c(v=vs.71).aspx

and read the topic "channel file" in the link you provided to find out more.

0
source

Source: https://habr.com/ru/post/1395347/


All Articles