gpt4 book ai didi

asp.net - 配置错误 'Facebook.FacebookConfigurationSection'

转载 作者:行者123 更新时间:2023-11-30 05:29:16 25 4
gpt4 key购买 nike

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

网站运行良好。但是每当我在 IIS 中部署它时,应用程序都会给我错误。

更改所有值后,错误的根本原因是更改应用程序池中的“空闲超时”。

这是我为重现此错误所做的操作:

1.构建网站并让它通过 IIS 运行。(在 visual studio 中通过更改网站属性以在自定义网络服务器中运行)。

2.将应用程序池中的空闲超时(在高级设置中)更改为 1 或 2 分钟。

3.运行网站,通过facebook登录。然后不要刷新它。 1 或 2 分钟后,您将收到此错误。

错误:

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><br/>
Line 9: <configSections><br/>
Line 10: <section name="facebookSettings"> type="Facebook.FacebookConfigurationSection"/><br/>
Line 11: </configSections><br/>
Line 12: <connectionStrings>

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

页面详细信息:

<%@ 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>

代码 Conceal :

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 文件:

<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>

最佳答案

在 Facebook C# SDK 4.2.1 中,我通过创建一个 FacebookSettings 的实例解决了这个错误,明确地在其中设置了应用程序 ID 和 key (我将它们保存在常规配置的 AppSettings 部分) 并将此显式设置实例传递给 FacebookApp 构造函数。

例子:

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

当我在没有 Web 上下文的情况下从 C# 单元测试项目运行代码时,我发生了这个错误。
我不需要在网站代码中遇到这个麻烦。

关于asp.net - 配置错误 'Facebook.FacebookConfigurationSection',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4716849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com