简体   繁体   English

在 ASP.NET Core MVC 应用程序的布局布局页面中存储个人资料图片、姓名、职位

[英]Storing profile picture, name, Job Title in layout layout Page of ASP.NET Core MVC app

I'm building my first web app and have completed the login mechanism to Azure using Identity web/OIDC.我正在构建我的第一个 web 应用程序,并使用 Identity web/OIDC 完成了 Azure 的登录机制。 I get the profile picture full name and job title using the Graph API.我使用 Graph API 获得了个人资料图片的全名和职位。

I'm not sure what is the best way to store the profile picture, name and job title in the layout page.我不确定在布局页面中存储个人资料图片、姓名和职位的最佳方式是什么。 When my app starts up I make a call to graph and copy the photograph to the www root folder to avoid constantly calling graph every time the layout page is called.当我的应用程序启动时,我调用图形并将照片复制到 www 根文件夹,以避免每次调用布局页面时不断调用图形。 I could also collect the name and job title at this point as well but I'm not sure where to store this information for later retrieval.此时我也可以收集姓名和职位,但我不确定将这些信息存储在哪里以供以后检索。 Can it be stored in memory, which I can then reference from the layout page?它可以存储在 memory 中,然后我可以从布局页面中引用它吗?

Here is part of my layout code这是我的布局代码的一部分

<div class="sidebar-header d-flex align-items-center">
    <div class="avatar"><img src="~/img/avatar.jpg" alt="Avatar" class="img-fluid rounded-circle"></div>

    <div class="title">
        <h1 class="h4">Full name</h1>
        <p>Job Title</p>                   
    </div>
</div>

<ul class="list-unstyled">

<li><a asp-area="" asp-controller="graph" asp-action="Profile"> <i class="fas fa-user" aria-hidden="true"></i>My Profile </a></li>
<li><a asp-area="" asp-controller="Dashboard" asp-action="Index"> <i class="fas fa-chart-line" aria-hidden="true"></i>Dashboard </a></li>

I'd appreciate any advice/example on best ways to achieve this.对于实现这一目标的最佳方法的任何建议/示例,我将不胜感激。

I'm using ASP.NET Core 3.1 MVC, Web Identity preview and Graph 3.7.0我正在使用 ASP.NET Core 3.1 MVC、Web Identity preview 和 Graph 3.7.0

Thanks,谢谢,

Jono城野

You may try to use the in-memory cache in ASP.NET Core .您可以尝试使用ASP.NET Core 中的内存缓存

On the other hand, if the profile picture is not that big, you can convert it into a base64 string and store it in the browser's localStorage together with the name and the job title.另一方面,如果头像不是那么大,你可以将其转换为 base64 字符串,并将其与名称和职位一起存储在浏览器的localStorage中。 Erase it when user logout.用户注销时将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM