在ASP.NET中使用Messenger Connect客户端库时出现Javascript错误

时间:2010-11-18 09:03:43

标签: javascript asp.net asp.net-ajax sitefinity liveid

我在现有Sitefinity网站内实施新的Messenger Connect功能时遇到问题,无法使用Live ID启用客户端登录。

即,当我使用以下代码实现客户端功能时:

<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="<%= ConfigurationManager.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>

...我在Firebug中遇到三个我无法正确识别的错误:

  

Sys.ArgumentTypeException:'Sys._Application'类型的对象不能   转换为'Sys.IDisposable'类型。   参数名称:object

(在ScriptResource.axd?d = ....第4993行)

  

Sys.Application._doInitialize不是   功能

(在MicrosoftAjaxBase.js第1行中)

  

Sys.InvalidOperationException:The   脚本'MicrosoftAjaxGlobalization.js'   已被多次引用。如果   引用Microsoft AJAX脚本   显式,设置MicrosoftAjaxMode   ScriptManager的属性   明确的。

(在ScriptResource.axd?d = ....第984行)

只有当我从js.live.net包含loader.js脚本时才会触发错误。

编辑:似乎错误不一定按该顺序触发。刷新页面似乎会混淆这些错误和/或引入其他错误,例如1842行Sys.ParameterCountException中的ScriptResource.axd?...

1 个答案:

答案 0 :(得分:3)

嘿,我在这里尝试了一些组合,而那个有效的组合是:

1)将ScriptManager的ScriptMode属性设置为 Release ;

2)使用ClientScript类在CodeBehind Page_Load事件中加载MSN库:

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

Firebug不再显示任何错误,在我的情况下,验证窗口会根据需要打开。

希望它有所帮助!

修改

如前所述,这里是我用来避免这个问题的全部代码:

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>

要查看它正在运行,您可以访问http://labs.asteria.com.br/wlm。似乎同意网址(https://consent.live.com/AccessToken.aspx)目前没有响应。