我正在建立我的第一个Facebook应用程序,我遇到了问题,我对这件事情太过新了解了解最新情况,并希望有经验的人可以理解.这是应用程序的链接,以及错误:
http://apps.facebook.com/nowiknow/
错误:
HTTP Error 500.23 – Internal Server
Error An ASP.NET setting has been
detected that does not apply in
Integrated managed pipeline mode.
我在DiscountASP.Net(littleappbin.com/whoremovedme/)上托管我的应用程序.我的应用程序池管道模式配置为Integrated,服务器使用IIS7.据我所知,我的代码成功请求了所需的权限,但是当被重定向到应用程序时出错了.
这是我的web.config文件:
<configuration>
<configSections>
<section type="Facebook.FacebookConfigurationSection, Facebook" name="facebookSettings" allowLocation="true" allowDefinition="Everywhere" />
<section name="canvasSettings" type="Facebook.Web.CanvasConfigurationSettings, Facebook.Web" />
</configSections>
<facebookSettings appSecret="xxxxxxxxxx" appId="xxxxxxxxxxxxxx" cookieSupport="true"/>
<canvasSettings canvasPageUrl="http://apps.facebook.com/nowiknow" canvasUrl="http://www.littleappbin.com/whoremovedme" authorizeCancelUrl="http://facebook.com"/>
<system.web>
<compilation debug="true" targetFramework="4.0" urlLinePragmas="true">
<assemblies>
<add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.DirectoryServices.Protocols, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.RegularExpressions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Entity.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.ServiceModel.Web, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.Services.Client, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Services.Design, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
<buildProviders>
<add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider"/>
</buildProviders>
</compilation>
<httpHandlers>
<add verb="*" path="facebookredirect.axd" type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web" />
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="facebookredirect.axd" verb="*" path="facebookredirect.axd" type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web" />
</handlers>
</system.webServer>
<connectionStrings>
<add name="xxxxxConnectionString" connectionString="Data Source=xxxxx;Initial Catalog=xxxxx;Persist Security Info=True;User ID=xxxxx;Password=xxxxxx" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
这是我页面后端的C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook;
using Facebook.Web;
using System.Collections;
public partial class _Default : Page
{
protected string requiredAppPermissions = "offline_access,user_about_me";
protected FacebookApp fbApp;
protected CanvasAuthorizer authorizer;
protected void Page_Load(object sender, EventArgs e)
{
fbApp = new FacebookApp();
authorizer = new CanvasAuthorizer(fbApp);
authorizer.Perms = requiredAppPermissions;
if (authorizer.Authorize())
{
//Authorized!
dynamic myInfo = fbApp.Get("me");
lblName.Text = "<b>" + myInfo.name + "</b>!";
UpdatePanel1.Visible = false;
}
}
private void ShowFacebookContent()
{
if (!Page.IsPostBack)
{
dynamic myInfo = fbApp.Get("me");
JsonArray myFriends = (JsonArray)((JsonObject)fbApp.Get("me/friends"))["data"];
lblFriendCount.Text = "<b>" + myFriends.Count.ToString() + "</b>";
//Record any new facebook friends
AddFacebookFriends(myInfo.id, myFriends);
//Populate the Previous friends DDL
PopulatePreviousFriendsDDL(myInfo.id);
//Populate the New Friends DDL
PopulateNewFriendsDDL(myFriends);
//Display the Missing Friends list
CalculateMissingFriends();
}
}
private void CalculateMissingFriends()
{
bool matched;
foreach (ListItem oldFriend in ddlPreviousFriends.Items)
{
matched = false;
foreach (ListItem newFriend in ddlNewFriends.Items)
{
if (oldFriend.Value == newFriend.Value)
{
matched = true;
break;
}
}
if (!matched)
{
//This friend has either been deleted, or has deleted the user
dynamic friendData = fbApp.Get(oldFriend.Value);
lblMissingFriends.Text += "<a href='" + friendData["link"].ToString() + "' target='_blank'>" + oldFriend.Text + "</a><br/>";
}
}
if (String.IsNullOrEmpty(lblMissingFriends.Text))
{
lblMissingFriends.Text = "No Friends are missing!";
}
}
private void PopulateNewFriendsDDL(JsonArray friends)
{
foreach (JsonObject friend in friends)
{
ddlNewFriends.Items.Add(new ListItem(friend["name"].ToString(), friend["id"].ToString()));
}
}
private void PopulatePreviousFriendsDDL(string userID)
{
FriendsDataContext friendDb = new FriendsDataContext();
var query = from dbFriends in friendDb.Friends
where dbFriends.UserID == userID
select dbFriends.FriendID;
ListItem friendItem;
foreach (string friendID in query)
{
dynamic friend = fbApp.Get(friendID);
ddlPreviousFriends.Items.Add(new ListItem(friend["name"].ToString(), friendID));
}
}
private void AddFacebookFriends(string userID, JsonArray friends)
{
FriendsDataContext friendDb = new FriendsDataContext();
var query = from dbFriends in friendDb.Friends
where dbFriends.UserID == userID
select dbFriends.FriendID;
bool matched;
string lastFriendID = String.Empty;
foreach (JsonObject friend in friends)
{
matched = false;
lastFriendID = friend["id"].ToString();
foreach(string friendID in query)
{
if (lastFriendID == friendID)
{
matched = true;
break;
}
}
if (!matched)
{
//Add this friend
friendDb.Friends.InsertOnSubmit(new Friend { ID = System.Guid.NewGuid().ToString(), UserID = userID, FriendID = lastFriendID });
}
}
friendDb.SubmitChanges();
}
protected void btnRecordFriends_Click(object sender, EventArgs e)
{
btnRecordFriends.Visible = false;
ShowFacebookContent();
UpdatePanel1.Visible = true;
}
}
我为这个凌乱的代码道歉,其中很大一部分是来自我正在讨厌的不同样本.
最佳答案 基本上,你把一大堆混合在一起的东西放在一起.具体来说,列出的所有程序集都是.net 3.5程序集,但您的编译设置为4.0.将您的web.config文件更改为:
<configuration>
<configSections>
<section type="Facebook.FacebookConfigurationSection, Facebook" name="facebookSettings" allowLocation="true" allowDefinition="Everywhere" />
<section name="canvasSettings" type="Facebook.Web.CanvasConfigurationSettings, Facebook.Web" />
</configSections>
<facebookSettings appSecret="xxxxxxxxxx" appId="xxxxxxxxxxxxxx" cookieSupport="true"/>
<canvasSettings canvasPageUrl="http://apps.facebook.com/nowiknow" canvasUrl="http://www.littleappbin.com/whoremovedme" authorizeCancelUrl="http://facebook.com"/>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="facebookredirect.axd" verb="*" path="facebookredirect.axd" type="Facebook.Web.FacebookAppRedirectHttpHandler, Facebook.Web" />
</handlers>
</system.webServer>
<connectionStrings>
<add name="xxxxxConnectionString" connectionString="Data Source=xxxxx;Initial Catalog=xxxxx;Persist Security Info=True;User ID=xxxxx;Password=xxxxxx" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
还要确保将Framework目标设置为4.0.有关详细信息,请参见此处:http://msdn.microsoft.com/en-us/library/bb398197.aspx