【问题标题】:How to access User.Identity.GetUserId() in Class library如何访问类库中的 User.Identity.GetUserId()
【发布时间】:2020-07-06 20:12:05
【问题描述】:

我将在我的 mvc.net Web 应用程序中使用一个类库作为数据层。是否可以从类库中访问 User.Identity.GetUserId()。

我可以使用 HttpContext.Current.User.Name 而不是 UserId 来访问用户名。

同时,在类库项目中无法访问 Microsoft.Aspnet.Identity 引用。

谢谢

【问题讨论】:

  • 如果你打算使用 GetUserId() 扩展方法。您必须添加 Microsoft.Aspnet.Identity 参考。

标签: asp.net-identity console-application class-library


【解决方案1】:

刚刚将 Microsoft.AspNet.Identity.Core.dll 添加到我的控制台应用程序引用中。不幸的是,此参考在参考列表和扩展中都不存在。我从我的 Web 应用程序的 bin 文件夹中借用了它。 我想知道为什么微软没有在参考列表中添加这个!

【讨论】:

    猜你喜欢
    • 2013-09-11
    • 1970-01-01
    • 1970-01-01
    • 2020-08-07
    • 2014-05-10
    • 2016-07-02
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多