I created a sample asp.net 4.0 application that includes a Facebook Connect button. I am running a website in IIS.
The site is working fine. But the application gives me an error whenever I deployed it to IIS.
After changing all values, the main cause of the error is to change the "idle timeout" in the application pool.
Here is what I did to reproduce this error:
1. Set up your site and let it work through IIS. (In a visual studio, changing the properties of a website to run in a user web server).
2. Change the idle timeout in the application pool (in advanced settings) to 1 or 2 minutes.
3. Launch the website, login via facebook. Then do not update it. After 1 or 2 minutes you will get this error.
Error:
Server error in application / Facebooktestjan2011.
Configuration Error Description: An error occurred while processing the configuration file necessary to service this request. Please read the specific error details below and modify the configuration file accordingly.
Parser error message: An error occurred creating the section handler configuration for facebookSettings: Failed to 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) { </script> </form> </body> </html>
Code for:
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>