我创建了一个示例asp.net 4.0应用程序,其中包含一个Facebook Connect按钮。我在IIS上运行该网站。
网站运行正常。但是每当我在IIS中部署它时,应用程序都会给我错误。
更改所有值后,错误的根本原因是更改应用程序池中的“空闲超时”。
以下是我为重现此错误所做的工作:
1.建立网站并让它通过IIS运行。(在Visual Studio中,通过更改网站属性以在自定义网络服务器中运行)。
2.将应用程序池中的空闲超时(在高级设置中)更改为1或2分钟。
3.运行网站,通过Facebook登录。然后不要刷新它。 1或2分钟后,您将收到此错误。
错误:
> Facebooktestjan2011'应用程序中的服务器错误。配置错误说明:An 处理过程中出错 需要的配置文件 服务这个请求。请查阅 下面的具体错误详情和 修改配置文件 适当。
分析程序错误消息:错误 发生了创建配置 facebookSettings的部分处理程序: 无法加载类型 'Facebook.FacebookConfigurationSection'。
来源错误:
Line 8: <configuration>
Line 9: <configSections>
Line 10: <section name="facebookSettings"> type="Facebook.FacebookConfigurationSection"/>
Line 11: </configSections>
Line 12: <connectionStrings>源文件:C:\ FacebooktestJan2011 \ web.config行: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>
答案 0 :(得分:2)
在Facebook C#SDK 4.2.1中,我通过创建FacebookSettings
的实例来解决错误,明确地将其设置为app Id和密钥(我将它们保存在常规的AppSettings部分中config)并将此显式设置实例传递给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#单元测试项目运行代码时,发生了这个错误 我不需要在网站代码中遇到这个问题。