配置错误“Facebook.FacebookConfigurationSection” [英] Configuration Error 'Facebook.FacebookConfigurationSection'

查看:200
本文介绍了配置错误“Facebook.FacebookConfigurationSection”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个示例asp.net 4.0应用程序,其中包括一个Facebook连接按钮。我在IIS上运行网站。

该网站工作正常。但是,应用程序给我的错误,每当我在IIS中部署它。

改变所有的值之后,错误的根本原因是通过更改应用程序池的空闲超时。

下面是我做过什么重现此错误:

1.Build网站,让它通过IIS(在网站的属性更改为自定义的Web服务器运行在Visual Studio)中运行。

2.Change在应用程序池空闲超时(高级设置)1或2分钟。

3.Run的网站,登录通过Facebook的。那就不要刷新。 1或2分钟后,你会得到这个错误。

错误:


  

在服务器错误/ Facebooktestjan2011应用程序。


  
  

配置错误说明:
  处理过程中出现错误
  需要的配置文件的
  此请求提供服务。请查阅
  下面的特定错误详细信息并
  修改配置文件
  适当。


  
  

分析器错误信息:错误
  发生创建配置
  对于facebookSettings节处理程序:
  未能加载类型
  Facebook.FacebookConfigurationSection。


  
  

源错误:


  
  


  8号线:<结构>结果
  9号线:其中; configSections>结果
  10号线:<节名称=facebookSettings>键入=Facebook.FacebookConfigurationSection/>结果
  11号线:LT; / configSections>结果
  第12行:其中,是connectionStrings>
  


  
  

源文件:C:\\ FacebooktestJan2011 \\ web.config行:10


页的详细信息:

 <%@页面语言=C#AutoEventWireup =真codeFILE =Default.aspx.cs
         继承=_默认%GT;!< D​​OCTYPE HTML PUBLIC - // W3C // DTD XHTML 1.0过渡// EN
       http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml
      的xmlns:FB =htt​​p://www.facebook.com/2008/fbml>
<头=服务器>
    <标题>< /标题>
< /头>
<身体GT;
    <表ID =form1的=服务器>
    < FB:登录按钮autologoutlink =真
                      onlogin =window.location.reload()
                      标题=Facebook连接>
     < / FB:登录按钮>
     < ASP:标签ID =lblFBStatus=服务器前景色=黑/>
        < D​​IV ID =FB-根>< / DIV>
        &所述; SCRIPT SRC =htt​​p://connect.facebook.net/en_US/all.js>&下; /脚本>
        <脚本>
        FB.init({APPID:APPID,状态:真的,饼干:真的,XFBML:真});
        FB.Event.subscribe('auth.sessionChange',函数(响应){
            如果(response.session){
                //用户已登录,一个新的cookie已经保存。
                // location.href =../TestFolder/Test.aspx;
            }其他{
                //用户已注销,而该cookie已被清除
            }
        });
        < / SCRIPT>
    < /表及GT;
< /身体GT;
< / HTML>


code背后:

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
使用System.Dynamic;
使用Facebook的;公共部分类FacebookTest:System.Web.UI.Page
{
    保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        FacebookApp fbApp =新FacebookApp();        如果(fbApp.Session!= NULL)
        {
            动态MyInfo的= fbApp.Get(我);
            字符串名字= myinfo.first_name;
            字符串姓氏= myinfo.last_name;
            lblFBStatus.Text =你登录的用户名为+姓名+
                               +姓氏+使用此凭证;        }
        其他
        {
            lblFBStatus.Text =请与Facebook在        }
    }
}


Web.config文件:

 <结构>
  < configSections>
    <节名称=facebookSettingsTYPE =Facebook.FacebookConfigurationSection/>
  < / configSections>
  < facebookSettings
     APPID =APPID
     appSecret =appsecret
     cookieSupport =真/>
  <&的System.Web GT;
    <编译调试=假targetFramework =4.0/>
      <&HttpHandlers的GT;
        <添加动词=*路径=facebookredirect.axd
             键入=Facebook.Web.FacebookAp predirectHttpHandler,Facebook.Web/>
      < / HttpHandlers的>  < /system.web>
  < system.webServer>
    <验证validateIntegratedModeConfiguration =FALSE/>
    <模块runAllManagedModulesForAllRequests =真/>    <&处理GT;
      <添加名称=facebookredirect.axd动词=*路径=facebookredirect.axd
          键入=Facebook.Web.FacebookAp predirectHttpHandler,Facebook.Web/>
    < /处理器>
  < /system.webServer>
< /结构>


解决方案

在Facebook的C#SDK 4.2.1,我周围的错误得到了通过 FacebookSettings 的一个实例,明确设置到它的应用程序ID和密钥的(我把它们配置的常规的AppSettings部分)的,并通过此明确设置实例的 FacebookApp 构造函数。

例如:

 使用Facebook的;VAR customSettings =新FacebookSettings();
customSettings.AppId =PUT_APP_ID_HERE;
customSettings.AppSecret =PUT_SECRET_HERE;FacebookApp fbApp =新FacebookApp(customSettings);
//成功对我来说

在我身上发生这个错误,当我从C#单元测试项目运行code,而不web环境present。结果
我并不需要去这个麻烦的网站code。

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>

解决方案

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.

这篇关于配置错误“Facebook.FacebookConfigurationSection”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆