Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 5 具有标识Server3 I';m无法根据其示例显示加载的用户详细信息_Asp.net Mvc 5_Identityserver3 - Fatal编程技术网

Asp.net mvc 5 具有标识Server3 I';m无法根据其示例显示加载的用户详细信息

Asp.net mvc 5 具有标识Server3 I';m无法根据其示例显示加载的用户详细信息,asp.net-mvc-5,identityserver3,Asp.net Mvc 5,Identityserver3,下面是IdentityServer3 jsGettingStarted示例 但我正在尝试使用MVC来实现这一点。 (根据示例文档,IdentityServer本身位于单独的项目和解决方案中。) 通过控制器操作提供index.html页面,这很好 登录弹出窗口“popup.html”,实际上是“popup.cshtml”,也通过控制器操作显示,但它不会关闭并在索引页中显示用户凭据,如示例所示。 但是在里面放一些警报。。用户肯定已登录 我还尝试将popup.html移到项目的根目录中(作为.html

下面是IdentityServer3 jsGettingStarted示例 但我正在尝试使用MVC来实现这一点。 (根据示例文档,IdentityServer本身位于单独的项目和解决方案中。)
通过控制器操作提供index.html页面,这很好

登录弹出窗口“popup.html”,实际上是“popup.cshtml”,也通过控制器操作显示,但它不会关闭并在索引页中显示用户凭据,如示例所示。
但是在里面放一些警报。。用户肯定已登录

我还尝试将popup.html移到项目的根目录中(作为.html而不是.cshtml,并更改服务器的Client.cs重定向URI以反映该更改),但没有成功

这是因为我的控制器操作提供了cshtml页面吗? 文档中说这应该通过调用display函数来显示,但是“manager.events.addUserLoaded”函数没有启动,它调用display函数

我正在使用VS2017 MVC5和框架4.8

谢谢

<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css" />
<script src="~/Scripts/jquery.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
<script src="~/Scripts/oidc-client.js"></script>

<div>
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <a class="navbar-brand" href="#">JS Application</a>
        </div>
    </div>
</nav>
<div class="container main-container">
    <div class="row">
        <div class="col-xs-12">
            <ul class="list-inline list-unstyled requests">
                <li><a href="index.html" class="btn btn-primary">Home</a></li>
                <li><button type="button" class="btn btn-default js-login">Login</button></li>
            </ul>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-6">
            <div class="panel panel-default">
                <div class="panel-heading">User data</div>
                <div class="panel-body">
                    <pre class="js-user"></pre>
                </div>
            </div>
        </div>
    </div>
</div>

  • 登录
用户数据


//帮助器函数向用户显示数据
功能显示(选择器、数据)
{
if(数据和类型数据==='string')
{
data=JSON.parse(数据);
}
如果(数据)
{
data=JSON.stringify(数据,null,2);
}
警报(“选择器=”+数据);
$(选择器)。文本(数据);
}
变量设置={
当局:'https://localhost:44302“,//标识服务器的url
客户端id:'js',
弹出\重定向\ uri:'http://localhost:44888/Account/Popup',
响应类型:“id\U令牌”,
范围:“openid配置文件电子邮件”,
filterProtocolClaims:正确
};
var manager=新的Oidc.UserManager(设置);
var用户;
manager.events.addUserLoaded(函数(loadedUser)
{
警报(“用户管理器”);
用户=loadedUser;
显示('.js user',user);
});
$('.js login')。在('click',函数()
{
经理
.signippup()
.catch(函数(错误)
{
console.error('通过当前窗口或弹出窗口登录时出错',错误);
});
});

通过创建一个独立的项目,而不是试图在已经建立的项目中完成它,我成功地让它工作起来。我们已经在使用的脚本和css中存在冲突

<script language="javascript" type="text/javascript">

// helper function to show data to the user
function display(selector, data)
{
    if (data && typeof data === 'string')
    {
        data = JSON.parse(data);
    }
    if (data)
    {
        data = JSON.stringify(data, null, 2);
    }

    alert("selector=" + data);
    $(selector).text(data);
}
var settings = {
    authority: 'https://localhost:44302',  // The url of the IdentityServer
    client_id: 'js',  
    popup_redirect_uri: 'http://localhost:44888/Account/Popup',
    response_type: 'id_token token',  
    scope: 'openid profile email',       
    filterProtocolClaims: true
};

var manager = new Oidc.UserManager(settings);
var user;

manager.events.addUserLoaded(function (loadedUser)
{
    alert("userManager");
    user = loadedUser;
    display('.js-user', user);   
});

$('.js-login').on('click', function ()
{
    manager
        .signinPopup()
        .catch(function (error)
        {
            console.error('error while logging in through the current window or popup', error);
        });
});
</script>