我创建了一个示例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>
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 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>
代码背后:
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实例来解决这个错误,明确地将其设置为app Id和密钥(我将它们保存在config的常规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#单元测试项目运行代码时,我发生了这个错误.
我不需要在网站代码中遇到这个问题.