Configuration Error 'Facebook.FacebookConfigurationSection'

我与影子孤独终老i 提交于 2019-12-13 13:25:34

问题


I created a sample asp.net 4.0 application which includes a Facebook Connect button. I run the website on IIS.

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

After changing all the values, the root cause of the error is by changing the "idle time-out" in the application pool.

Here is what I did to reproduce this error:

1.Build the site and let it run through IIS.(In visual studio by changing in the website properties to run in custom webserver).

2.Change the idle timeout in the application pool (in advanced setting) to 1 or 2 min.

3.Run the website, login through the facebook. Then don't refresh it. After 1 or 2 min, you will get this error.

ERROR:

Server Error in '/Facebooktestjan2011' Application.

Configuration Error Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: An error occurred creating the configuration section handler for facebookSettings: Could not 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 Behind:

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>

回答1:


In Facebook C# SDK 4.2.1, I got around the error by making an instance of FacebookSettings, explicitly setting into it the app Id and secret key (I kept them in the regular AppSettings section of config) and passed this explicit settings instance to 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 happened to me when I was running code from a C# unit test project without a web context present.
I didn't need to go to this trouble in the website code.



来源:https://stackoverflow.com/questions/4716849/configuration-error-facebook-facebookconfigurationsection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!