"Facebook.FacebookConfigurationSection" configuration error

I created a sample asp.net 4.0 application that includes a Facebook Connect button. I am running a website in IIS.

The site is working fine. But the application gives me an error whenever I deployed it to IIS.

After changing all values, the main cause of the error is to change the "idle timeout" in the application pool.

Here is what I did to reproduce this error:

1. Set up your site and let it work through IIS. (In a visual studio, changing the properties of a website to run in a user web server).

2. Change the idle timeout in the application pool (in advanced settings) to 1 or 2 minutes.

3. Launch the website, login via facebook. Then do not update it. After 1 or 2 minutes you will get this error.

Error:

Server error in application / Facebooktestjan2011.

Configuration Error Description: An error occurred while processing the configuration file necessary to service this request. Please read the specific error details below and modify the configuration file accordingly.

Parser error message: An error occurred creating the section handler configuration for facebookSettings: Failed to load type 'Facebook.FacebookConfigurationSection'.

Source Error:

Line 8: <configuration>
Line 9: <configSections>
Line 10: <section name="facebookSettings"> type="Facebook.FacebookConfigurationSection"/>
Line 11: </configSections>
Line 12: <connectionStrings>

Source file: C: \ FacebooktestJan2011 \ web.config Line: 10

Page Details:

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <fb:login-button autologoutlink='true' onlogin="window.location.reload()" Title="Facebook Connect"> </fb:login-button> <asp:label id="lblFBStatus" runat="server" ForeColor="black"/> <div id="fb-root"></div> <script src="http://connect.facebook.net/en_US/all.js"></script> <script> FB.init({ appId: 'appid', status: true, cookie: true, xfbml: true }); FB.Event.subscribe('auth.sessionChange', function (response) { if (response.session) { // A user has logged in, and a new cookie has been saved // location.href = "../TestFolder/Test.aspx"; } else { // The user has logged out, and the cookie has been cleared } }); </script> </form> </body> </html> 

Code for:

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Dynamic; using Facebook; public partial class FacebookTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { FacebookApp fbApp = new FacebookApp(); if (fbApp.Session != null) { dynamic myinfo = fbApp.Get("me"); String firstname = myinfo.first_name; String lastname = myinfo.last_name; lblFBStatus.Text = "you signed in as " + firstname + " " + lastname + " to use this credential "; } else { lblFBStatus.Text = "Please sign in with facebook"; } } } 

Web.config file:

 <configuration> <configSections> <section name="facebookSettings" type="Facebook.FacebookConfigurationSection"/> </configSections> <facebookSettings appId="appid" appSecret="appsecret" cookieSupport="true" /> <system.web> <compilation debug="false" targetFramework="4.0" /> <httpHandlers> <add verb="*" path="facebookredirect.axd" type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web" /> </httpHandlers> </system.web> <system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules runAllManagedModulesForAllRequests="true"/> <handlers> <add name="facebookredirect.axd" verb="*" path="facebookredirect.axd" type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web" /> </handlers> </system.webServer> </configuration> 
+4
source share
1 answer

In Facebook C # SDK 4.2.1, I circumvented the error by creating an instance of FacebookSettings , explicitly setting the application identifier and secret key into it (I saved them in the usual settings section of AppSettings) and passed this an explicit example of settings for the FacebookApp constructor.

Example:

 using Facebook; var customSettings = new FacebookSettings(); customSettings.AppId = "PUT_APP_ID_HERE"; customSettings.AppSecret = "PUT_SECRET_HERE"; FacebookApp fbApp = new FacebookApp(customSettings); // success for me 

This error occurred to me when I ran code from a C # unit test project without the presence of a web context.
I did not have to go to this problem in the site code.

+2
source

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


All Articles