开发者

Javascript error when using Messenger Connect client-side library in ASP.NET

开发者 https://www.devze.com 2023-01-25 11:02 出处:网络
I\'m having a problem implementing the new Messenger Connect functionality inside an existing Sitefinity site to enable client logins using Live IDs.

I'm having a problem implementing the new Messenger Connect functionality inside an existing Sitefinity site to enable client logins using Live IDs.

Namely, when I'm using the following code to implement the client-side functionality:

<head runat="server">
  <script type="text/javascript" src="http://js.live.net/4.1/loader.js"></script>
</head>
<body>
  <form runat="server" id="form1">
    <asp:ScriptManager ID="ScriptManager1" runat="server"/>
    <wl:app
        client-id="<%= ConfigurationMan开发者_JAVA百科ager.AppSettings["wl_wrap_client_id"] %>"
        scope="WL_Profiles.View"
        callback-url="<%= ConfigurationManager.AppSettings["wl_wrap_client_callback"] %>?wl_session_id=<%=SessionId %>"
        channel-url="/channel.htm">
    </wl:app>

... I get three errors in Firebug that I can't quite identify correctly:

Sys.ArgumentTypeException: Object of type 'Sys._Application' cannot be converted to type 'Sys.IDisposable'. Parameter name: object

(in ScriptResource.axd?d=.... line 4993)

Sys.Application._doInitialize is not a function

(in MicrosoftAjaxBase.js line 1)

Sys.InvalidOperationException: The script 'MicrosoftAjaxGlobalization.js' has been referenced multiple times. If referencing Microsoft AJAX scripts explicitly, set the MicrosoftAjaxMode property of the ScriptManager to Explicit.

(in ScriptResource.axd?d=.... line 984)

The errors are only triggered when I include the loader.js script from js.live.net.

EDIT: Seems the errors aren't necessarily triggered in that order. Refreshing the page seems to shuffle those errors and/or introduce other ones, such as a Sys.ParameterCountException in ScriptResource.axd?... on line 1842, for example.


Hey, I tried some combinations here, and the one that worked was:

1) Set the ScriptMode property of the ScriptManager to Release;

2) Load the MSN library in the CodeBehind Page_Load event, using the ClientScript class:

protected void Page_Load(object sender, EventArgs e)
{
    ClientScript.RegisterClientScriptInclude(this.GetType(), "live", "http://js.live.net/4.0/loader.js");
}

Firebug isn't showing any error anymore, and in my case, the authentication window is opening as desired.

Hope it helps!

EDIT

As told before, here follows the whole code I use to avoid this issue:

Default.aspx

<%@ 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:wl="http://apis.live.net/js/2010">
<head>
    <title>SignIn Example</title>
    <script type="text/javascript">
        function appLoaded(appLoadedEventArgs) {
        }
        function signInCallback(signInCompletedEventArgs) {
            if (signInCompletedEventArgs.get_resultCode() === Microsoft.Live.AsyncResultCode.success)
            {
                alert('Sign-in successful.');
            }
            else
            {
                alert('Sign-in failed.');
            }
        }
    </script>
</head>
<body>
    <form runat="server" id="form1">

    <asp:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Release"></asp:ScriptManager>

    <wl:app channel-url="http://labs.asteria.com.br/wlm/Channel.html" 
        callback-url="http://labs.asteria.com.br/wlm/Callback.aspx?wl_session_id=<%= Session.SessionID %>"
        client-id="0000000044052209" 
        scope="WL_Profiles.View" 
        onload="{{appLoaded}}">
    </wl:app>
    <wl:signin 
        id="signInControl" 
        signedintext="Signed in. Click to sign out." 
        signedouttext="Click to sign in."
        onsignin="{{signInCallback}}" />
    </form>
</body>
</html>

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ClientScript.RegisterClientScriptInclude(this.GetType(), "live", "http://js.live.net/4.0/loader.js");
    }
}

Web.config

<?xml version="1.0"?>
<configuration>
<appSettings>
    <add key="wl_wrap_client_secret" value="[YOUR SECRET KEY]"/>
    <add key="wl_wrap_client_id" value="0000000044052209"/>
    <add key="wl_wrap_client_callback" value="http://labs.asteria.com.br/wlm/Callback.aspx"/>
</appSettings>

<connectionStrings/>
<system.web>
    <customErrors mode="Off"/>
    <compilation debug="true" targetFramework="4.0"></compilation>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
</configuration>

To see it running, you can access http://labs.asteria.com.br/wlm. It seems that the Consent URL (https://consent.live.com/AccessToken.aspx) is not responding at this time.

0

精彩评论

暂无评论...
验证码 换一张
取 消