An attempt was made to access a socket in a way forbidden by its access permissions

rouen picture rouen · Jan 25, 2011 · Viewed 54.5k times · Source

I just downloaded C# SDK and ASP.NET MVC sample, modified it to work with 4.2.1. (web config facebookSettings parameters etc.), created my Facebook application and tried to run it. Click to facebook login button - ok, entering credentials into facebook popup - ok, allowing access for my application - ok, and then I get this error:

System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 66.220.146.47:443

var app = new FacebookApp();
if (app.Session == null)
{
   // The user isnt logged in to Facebook
   // send them to the home page
   return RedirectToAction("Index");
}

// Get the user info from the Graph API
dynamic me = app.Api("/me"); // EXCEPTION THROWN HERE
ViewData["FirstName"] = me.first_name;
ViewData["LastName"] = me.last_name;

The app object is OK I think (containing settings params, session object with access token and my facebook userid, etc.)

I am using local development address http://myappdev.local (set to 127.0.0.1 in hosts file). The same address is set in my facebook app settings, also domain myappdev.local - Can this be the problem? I have seen examples using localhost:1234 in some tutorials.

Answer

Robotnik picture Robotnik · Dec 17, 2013

If you're getting the same error in Windows 8 development, it could be that you haven't enabled access over Private Networks in your Package.appxmanifest file:

Highlighting the Private Networks (Client & Server) option