Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.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 用用户模型填充模型_Asp.net_Asp.net Core - Fatal编程技术网

Asp.net 用用户模型填充模型

Asp.net 用用户模型填充模型,asp.net,asp.net-core,Asp.net,Asp.net Core,我使用的是oauth策略,它从dotnet填充内置用户模型。现在,我想用这个用户模型填充我自己的模型,然后从使用oauth的第三方服务提供的API获取更多信息。现在我有点困惑如何用用户填充我自己的模型。我该怎么做呢。除此之外,还要使用MVC架构 控制器 namespace AspNetCoreGitHubAuth.Controllers { [Authorize] [Route("[controller]/[action]")] public clas

我使用的是oauth策略,它从dotnet填充内置用户模型。现在,我想用这个用户模型填充我自己的模型,然后从使用oauth的第三方服务提供的API获取更多信息。现在我有点困惑如何用用户填充我自己的模型。我该怎么做呢。除此之外,还要使用MVC架构

控制器

namespace AspNetCoreGitHubAuth.Controllers
{
    [Authorize]
    [Route("[controller]/[action]")]
    public class TestController : Controller
    {
        [HttpGet]
        public ActionResult Welcome()
        {
            Console.WriteLine("---------------------");
            return View();
        }
欢迎使用.cshtml

@{
    ViewData["Title"] = "test welcome";
}
// i want to display the user info on this page
<h2>test welcome</h2>
@{
ViewData[“Title”]=“测试欢迎”;
}
//我想在此页面上显示用户信息
测试欢迎
模型

名称空间AspNetCoreGitHubAuth.Models
{
公共类Github
{
公共类索引模型
{
公共字符串GitHubAvatar{get;set;}
公共字符串GitHubLogin{get;set;}
公共字符串GitHubName{get;set;}
公共字符串GitHubUrl{get;set;}
公共IReadOnlyList存储库{get;set;}
//公共异步任务OnGetAsync()
//{
/*if(User.Identity.IsAuthenticated)
{
GitHubName=User.FindFirst(c=>c.Type==ClaimTypes.Name)?.Value;
GitHubLogin=User.FindFirst(c=>c.Type==“urn:github:login”)?.Value;
GitHubUrl=User.FindFirst(c=>c.Type==“urn:github:url”)?.Value;
GitHubAvatar=User.FindFirst(c=>c.Type==“urn:github:avatar”)?.Value;
string accessToken=await HttpContext.GetTokenAsync(“访问令牌”);
var github=new-GitHubClient(new-ProductHeaderValue(“aspnetcoregthubauth”)、new-InMemoryCredentialStore(new-Credentials(accessToken));
Repositories=wait github.Repository.GetAllForCurrent();
}*/
//}
}
}
}

这将帮助您:您可以从startup.cs分享您的服务方法吗?您提供的链接使用razorpages。这与查看页面略有不同,因为razor页面中的模型可以扩展pageModel类,该类允许您使用onGetAsync来执行抓取,suchMy statup.cs是您提供的链接中startup.cs文件的精确副本:)好,我的建议是,在尝试使用它的任何值之前,尝试使用持久化用户从GitHub端点接收的ILogger和log。这只是为了看看它是否真的返回了所有这些值。这将帮助您:您可以从startup.cs共享您的服务方法吗?您提供的链接使用razorpages。这与查看页面略有不同,因为razor页面中的模型可以扩展pageModel类,该类允许您使用onGetAsync来执行抓取,suchMy statup.cs是您提供的链接中startup.cs文件的精确副本:)好,我的建议是,在尝试使用它的任何值之前,尝试使用持久化用户从GitHub端点接收的ILogger和log。这只是为了看看它是否真的返回了所有这些值。
namespace AspNetCoreGitHubAuth.Models
{
    public class Github
    {
        public class IndexModel
        {
            public string GitHubAvatar { get; set; }

            public string GitHubLogin { get; set; }

            public string GitHubName { get; set; }

            public string GitHubUrl { get; set; }

            public IReadOnlyList<Repository> Repositories { get; set; }

            //public async Task OnGetAsync()
            //{
                /*if (User.Identity.IsAuthenticated)
                {
                    GitHubName = User.FindFirst(c => c.Type == ClaimTypes.Name)?.Value;
                    GitHubLogin = User.FindFirst(c => c.Type == "urn:github:login")?.Value;
                    GitHubUrl = User.FindFirst(c => c.Type == "urn:github:url")?.Value;
                    GitHubAvatar = User.FindFirst(c => c.Type == "urn:github:avatar")?.Value;

                    string accessToken = await HttpContext.GetTokenAsync("access_token");

                    var github = new GitHubClient(new ProductHeaderValue("AspNetCoreGitHubAuth"), new InMemoryCredentialStore(new Credentials(accessToken)));
                    Repositories = await github.Repository.GetAllForCurrent();

                }*/
            //}
        }
    }
}