To post status on Facebook using ASP.NET, we must have a valid Facebook account. We need to create a Facebook App first to get App Id and Secret Key.
Steps to create Facebook App to receive App Id and Secret Key
In order to get an App Id and Secret key we need to register a new application
Visit Facebook Developer Page as in the following screenshot:
Register yourself as Facebook Developer.
After registration as Facebook Developer,
Click Register:
Create New App,
We will choose Website as a platform to get started and thereby App Id and Secret Key will be generated.
After selecting Website as a platform, the following screen appears. In the top right, look for the button “Skip and Create App ID” and click it.
Clicking the “Skip and Create App ID” button will bring up the following screen.
You need to fill out Display Name and select a Category. Here we gave “Traffic Cop” display name.
You can ignore the Namespace field as this is not necessary for our purpose. Select the category of the app. Here we used News as the category of the app.
After following above steps, we will be redirected to the following screen. On this screen we can see App Id and App Secret in two fields at the top. App Secret is in password format. Click the “Show” button, this will display App Secret Key.
After clicking Show button, we can see the App Secret Key thereby can use in in our application.
These Facebook App Id and App Secret Key is used in the application from where we wish to make Facebook post.

After applying App Id and App Secret, we can now post on Facebook wall.
Let's say, we have the following front end screen.
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <link href="bootstrap.min.css" rel="stylesheet" />
- </head>
- <body>
- <form id="form1" runat="server" style="margin-top:40px;">
- <div>
- <asp:FileUpload ID="FileUpload1" runat="server" style="margin-left: 538px;" />
- <br />
- <br />
- <asp:TextBox ID="txtMessage" runat="server" TextMode = "MultiLine" CssClass="col-xs-4" style="margin-left: 538px;" ></asp:TextBox>
- <br />
- <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick = "UploadPhoto" style="margin-left: 538px;" CssClass="btn" />
- </div>
- </form>
- </body>
- </html>

User can choose image file and add caption to the same and upload it to the Facebook wall using Facebook App.
Backend Snippet
- public partial class CS : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- FaceBookConnect.API_Key = "enter App Id here";
- FaceBookConnect.API_Secret = "enter App Secret here";
- if (!IsPostBack)
- {
- string code = Request.QueryString["code"];
- if (!string.IsNullOrEmpty(code))
- {
- if (Session["File"] != null)
- {
- FaceBookConnect.PostFile(code, "me/photos", (HttpPostedFile)Session["File"], Session["Message"].ToString());
- }
- else
- {
- Dictionary<string, string> data = new Dictionary<string, string>();
- data.Add("message", Session["Message"].ToString());
- FaceBookConnect.Post(code, "me/feed", data);
- }
- Session["File"] = null;
- Session["Message"] = null;
- }
- }
- }
- protected void UploadPhoto(object sender, EventArgs e)
- {
- if (FileUpload1.HasFile)
- Session["File"] = FileUpload1.PostedFile;
- Session["Message"] = txtMessage.Text;
- FaceBookConnect.Authorize("user_photos,publish_actions", Request.Url.AbsoluteUri.Split('?')[0]);
- }
- }

In this way, we implemented a demo how we can post on Facebook using App Id and App Secret account of Facebook App. Hope you like it.

VishakhPosted Dec 6, 2022, 7:36 AM
I get error as Can't load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and sub-domains of your app to the App Domains field in your app settings.
immad uddinPosted Jul 3, 2020, 8:19 AM
Hello ....... ...... Invalid Scopes: publish_stream, manage_pages. This message is only shown to developers. Users of your app will ignore these permissions if present. Please read the documentation for valid permissions at: https://developers.facebook.com/docs/facebook-login/permissions
Dinesh GabhanePosted Nov 11, 2019, 1:17 AM
Good One.....
Sundaram SubramanianPosted Dec 28, 2018, 10:08 AM
Nice work. Thanks for sharing this.
amr ismailPosted Apr 8, 2017, 7:49 PM
Can we use your code to post in groups using groupid?
saranya saranPosted Mar 19, 2017, 7:02 AM
How am download this project?
Manav PandyaPosted Jan 7, 2017, 2:51 AM
Do you have this demo using asp.net mvc ????
Rajesh CenturaPosted Nov 4, 2016, 4:06 AM
What namespace should be added for backend?
Aumkar NaikPosted Jul 20, 2016, 6:15 AM
Replay imm
Aumkar NaikPosted Jul 20, 2016, 6:14 AM
What to add namespace for facebook in code behind
Kashif SohailPosted Mar 21, 2016, 10:49 PM
Very nice
Vignesh ManiPosted Mar 16, 2016, 5:59 PM
nice