将 openId 选择器与 Asp.Net MVC 2 集成时出现问题

发布于 2024-10-04 21:06:53 字数 3207 浏览 3 评论 0原文

我正在尝试使用 openid 选择器 javascript 库来允许 OpenId 登录网站。我正在按照此网站上的说明进行操作,但是我通常不是网络程序员,它不起作用,我不确定为什么。我确信这是相当微不足道的事情,但我看不到它。

问题是没有带有 open Id 位的图像渲染在它应该去的地方,即

I'我假设。这似乎表明应该设置此 div 内容的函数没有运行。

我怀疑剧本。

我已经添加了对 Site.Master 的脚本引用,如下所示:

<script type="text/javascript" src="../../Scripts/jquery-1.4.1.min.js"></script>  
<script type="text/javascript" src="../../Scripts/openid-jquery.js"></script>  
<script type="text/javascript">
    $(document).ready(function () {
        alert("document ready"); // <- I added this to verfiy that this is being called
        openid.init('openid_identifier');
    });  
</script>  

它似乎在每个页面上调用该函数(显示警报),然后我认为应该调用 openid.init 函数。

这是在 openid-jquery.js 脚本中定义的:

var openid = {    
version: '1.2', // version constant
demo: false,
demo_text: null,
cookie_expires: 6 * 30, // 6 months.
cookie_name: 'openid_provider',
cookie_path: '/',

img_path: '../images/',
lang: null, // language, is set in openid-jquery-<lang>.js
signin_text: null, // text on submit button on the form
input_id: null,
provider_url: null,
provider_id: null,
all_small: false, // output large providers w/ small icons
no_sprite: false, // don't use sprite image
image_title: '{provider}', // for image title

init: function (input_id) {
    alert("initialising");
    providers = $.extend({}, providers_large, providers_small);

    var openid_btns = $('#openid_btns');

    this.input_id = input_id;

    $('#openid_choice').show();
    $('#openid_input_area').empty();

    var i = 0;
    // add box for each provider
    for (id in providers_large) {
        if (this.all_small) {
            openid_btns.append(this.getBoxHTML(id, providers_large[id], 'small', i++));
        } else
            openid_btns.append(this.getBoxHTML(id, providers_large[id], 'large', i++));
    }
    if (providers_small) {
        openid_btns.append('<br/>');

        for (id in providers_small) {

            openid_btns.append(this.getBoxHTML(id, providers_small[id], 'small', i++));
        }
    }

    $('#openid_form').submit(this.submit);

    var box_id = this.readCookie();
    if (box_id) {
        this.signin(box_id, true);
    }

我再次添加了 alert("initialising"); ,它似乎从未被调用。

应该调用这个函数吗?我怎样才能确定为什么这个函数没有被调用?有什么想法吗?

更新:

在文档就绪函数中,我交换了函数的顺序,如下所示:

<script type="text/javascript">
    $(document).ready(function () {            
        openid.init('openid_identifier');
        alert("document ready"); 
    });  
</script>  

现在不会引发警报。这是什么意思?其他功能出了问题吗?我怎么知道它是什么?

更新2:

奇怪。如果我将 openid-jquery.js 文件重命名为其他名称(似乎是任何名称)(例如 openid-jquery.2.js),那么我可以从 open id 脚本中看到警报。

但它似乎只执行警报,而不执行下一行,因为当我稍后添加另一个更改时(即在下一行之后),从未看到第二个警报。也不知道为什么会这样。

更新3: 在 Chrome 中调试后,问题似乎是 providers_large、providers_small 未定义,并

var providers_large;
var providers_small;

在脚本顶部添加: 允许它至少运行并显示警报。但仍然没有图像...我认为需要进一步调查。

I am trying to use the openid selector javascript library to allow OpenId login for a web site. I'm following the instructions on this site, but I'm not usually a web programmer and its not working and I'm not certain why. I'm sure its something fairly trivial but I can't see it.

The problem is that no image with the open Id bits on it is rendered in the place where it should go, which is the <div id="openid_btns"></div> I'm assuming. This seems to indicate to me that the function which is supposed to set the contents of this div is not being run.

I suspected the scripts.

I have added the script references to the Site.Master as it indicates:

<script type="text/javascript" src="../../Scripts/jquery-1.4.1.min.js"></script>  
<script type="text/javascript" src="../../Scripts/openid-jquery.js"></script>  
<script type="text/javascript">
    $(document).ready(function () {
        alert("document ready"); // <- I added this to verfiy that this is being called
        openid.init('openid_identifier');
    });  
</script>  

and it seems to call the function on each page (the alert is shown) and it should then, I assume, call the openid.init function.

this is defined in the openid-jquery.js script:

var openid = {    
version: '1.2', // version constant
demo: false,
demo_text: null,
cookie_expires: 6 * 30, // 6 months.
cookie_name: 'openid_provider',
cookie_path: '/',

img_path: '../images/',
lang: null, // language, is set in openid-jquery-<lang>.js
signin_text: null, // text on submit button on the form
input_id: null,
provider_url: null,
provider_id: null,
all_small: false, // output large providers w/ small icons
no_sprite: false, // don't use sprite image
image_title: '{provider}', // for image title

init: function (input_id) {
    alert("initialising");
    providers = $.extend({}, providers_large, providers_small);

    var openid_btns = $('#openid_btns');

    this.input_id = input_id;

    $('#openid_choice').show();
    $('#openid_input_area').empty();

    var i = 0;
    // add box for each provider
    for (id in providers_large) {
        if (this.all_small) {
            openid_btns.append(this.getBoxHTML(id, providers_large[id], 'small', i++));
        } else
            openid_btns.append(this.getBoxHTML(id, providers_large[id], 'large', i++));
    }
    if (providers_small) {
        openid_btns.append('<br/>');

        for (id in providers_small) {

            openid_btns.append(this.getBoxHTML(id, providers_small[id], 'small', i++));
        }
    }

    $('#openid_form').submit(this.submit);

    var box_id = this.readCookie();
    if (box_id) {
        this.signin(box_id, true);
    }

again I added the alert("initialising"); which never seems to be called.

Should it be calling this function? How can I determine why this function is not being called? Any ideas?

UPDATE:

in the document ready function i swapped the order of the functions like so:

<script type="text/javascript">
    $(document).ready(function () {            
        openid.init('openid_identifier');
        alert("document ready"); 
    });  
</script>  

and now the alert is not raised. what does this mean? is something going wrong in the other function? how can I tell what it is?

UPDATE 2:

Wierd. If I rename the openid-jquery.js file to something (seemingly anything) else (like openid-jquery.2.js) then I can see the alert from the open id script.

but it only seems to execute the alert and not the next line as when I add another alter later on (ie after the very next line) the 2nd alert is never seen. not sure why that would be either.

UPDATE 3:
After debugging in chrome it seems the problem was that providers_large, providers_small were not defined and adding:

var providers_large;
var providers_small;

to the top of the script allowed it to at least run and show the alerts. but still no images... further investigation I think.

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

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

发布评论

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

评论(3

橙味迷妹 2024-10-11 21:06:53

因此,似乎在说明的第 4 步中,需要更新它以添加英语 javascript 提供程序信息,这是定义 provider_large 的位置,如下所示:

<script type="text/javascript" src="../../Scripts/jquery-1.4.1.min.js"></script>  
<script type="text/javascript" src="../../Scripts/openid-jquery.js"></script> 
<script type="text/javascript" src="../../Scripts/openid-jquery-en.js"></script>  
<script type="text/javascript">
    $(document).ready(function () {
        alert("document ready"); // <- I added this to verfiy that this is being called
        openid.init('openid_identifier');
    });  
</script>  

so it seems that in step 4 of the instructions it needs to be updated to add the english javascript provider information which is where the provider_large is defined, like so:

<script type="text/javascript" src="../../Scripts/jquery-1.4.1.min.js"></script>  
<script type="text/javascript" src="../../Scripts/openid-jquery.js"></script> 
<script type="text/javascript" src="../../Scripts/openid-jquery-en.js"></script>  
<script type="text/javascript">
    $(document).ready(function () {
        alert("document ready"); // <- I added this to verfiy that this is being called
        openid.init('openid_identifier');
    });  
</script>  
秋风の叶未落 2024-10-11 21:06:53

对 Sam 在 1.3 版本中的回答进行了轻微更新。

解压文件:

C:\Blah\openid-selector-1.3\openid-selector\js\openid-en.js

脚本标签:

Slight update to Sam's answer above for version 1.3.

Unzipped Files:

C:\Blah\openid-selector-1.3\openid-selector\js\openid-en.js

Script Tag:

<script type="text/javascript" src="../../Scripts/openid-en.js"></script>

凶凌 2024-10-11 21:06:53

我遇到了同样的问题,检查您的 web.config 并将所有用户的权限添加到这些新目录,然后工作

I had the same problem, check your web.config and add permission to all users to those new directories, and then works

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