Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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 web应用程序关联的Azure WebJob无法从WebJob访问用户角色_Asp.net_Asp.net Mvc_Azure_Asp.net Identity_Azure Webjobs - Fatal编程技术网

与ASP.NET web应用程序关联的Azure WebJob无法从WebJob访问用户角色

与ASP.NET web应用程序关联的Azure WebJob无法从WebJob访问用户角色,asp.net,asp.net-mvc,azure,asp.net-identity,azure-webjobs,Asp.net,Asp.net Mvc,Azure,Asp.net Identity,Azure Webjobs,背景: ASP.NET Web应用程序管理用户、角色和用户在其活动服务上花费的用户信用。webjob定期检查用户使用的服务,并相应地更新他们的信用。WebJob执行的CreditUpdate操作在更新信用时还应考虑用户角色 问题:我无法从web作业访问角色。在WebApp上,角色由ApplicationUserManagerclass:UserManager.GetRoles(user.Id)管理和访问。问题是WebJob无法访问UserManagerHttpContext.GetOwinCon

背景: ASP.NET Web应用程序管理用户、角色和用户在其活动服务上花费的用户信用。webjob定期检查用户使用的服务,并相应地更新他们的信用。WebJob执行的
CreditUpdate
操作在更新信用时还应考虑用户角色

问题:我无法从web作业访问角色。在WebApp上,角色由
ApplicationUserManager
class:
UserManager.GetRoles(user.Id)
管理和访问。问题是WebJob无法访问UserManager
HttpContext.GetOwinContext().GetUserManager()
,我也不知道如何从WebJob创建新实例

简而言之。访问身份数据库并拥有
应用程序用户的实例。您知道我如何访问与之关联的用户角色吗

以下是我的webjob代码,以防它有所帮助。文件是
Functions.cs

// This function will be triggered based on the schedule you have set for this WebJob
// This function will enqueue a message on an Azure Queue called queue
[NoAutomaticTrigger]
public static void ManualTrigger(TextWriter log, int value, [Queue("queue")] out string message)
{
    var db = new ApplicationDbContext();
    var users = db.Users.ToList();
    foreach (var user in users)
    {
        //I would like to check user role first
        //if (user.IsInRole("canruletheworld")) {}
        user.updateCredit();
    }

    log.WriteLine("Function is invoked with value={0}", value);
    message = value.ToString();
    log.WriteLine("Following message will be written on the Queue={0}", message);
}

只需构造UserManager的本地实例:

var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
var userManager=newusermanager(newuserstore(new ApplicationDbContext());

您是否查看了Azure AD Graph aPI?您可以使用它检索用户角色。如果你需要一些样品,请告诉我。那也许可以。但这比我想象的要复杂。当db连接已经在本地时,在网络上这样做似乎有点过头了。此外,如果该解决方案也能与我在开发过程中通常使用的本地数据库(在我的笔记本电脑上)配合使用,那就更好了