Приложение Facebook получает ошибку HTTP 500.23; Перевод? - PullRequest
4 голосов
/ 05 января 2011

Я создаю свое первое приложение для Facebook, и у меня возникла проблема, я слишком новичок во всем этом, чтобы понять, что происходит, и надеялся, что кто-то более опытный может понять. Вот ссылка на приложение и ошибка:

http://apps.facebook.com/nowiknow/

Ошибка:

Ошибка HTTP 500.23 - Внутренний сервер Ошибка Установлена ​​ASP.NET обнаружено, что не применяется в Интегрированный режим управляемого конвейера.

Я размещаю свое приложение на DiscountASP.Net (littleappbin.com/whoremovedme/). Мой пул приложений Режим конвейера настроен на Интегрирован , и сервер использует 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;
    }
}

Я прошу прощения за грязный код, большая часть которого взята из разных примеров, которыми я пользуюсь.

1 Ответ

2 голосов
/ 05 января 2011

По сути, у вас есть целая куча вещей, смешанных вместе, которые не сочетаются друг с другом. В частности, все ваши перечисленные сборки являются сборками .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

...