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

发布于 2024-10-02 17:34:08 字数 1473 浏览 6 评论 0原文

我在现有 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”。 参数名称:对象

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

Sys.Application._doInitialize 不是 功能

(在 MicrosoftAjaxBase.js 第 1 行中)

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

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

仅当我包含来自 js.live.net 的 loader.js 脚本时才会触发错误。

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

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

... 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里人 2024-10-09 17:34:08

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

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。同意 URL (https://consent.live.com/AccessToken.aspx) 此时似乎没有响应。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文