Skip to content

UserInfo

ansonzhang edited this page Oct 15, 2019 · 3 revisions

获取User info

注意:下边的代码在 netcore 3.0分支的,可以下载看看,但是同样适用于2.2,只不过master分支我没有修改而已。

对应的接口

Blog.Core.Common / HttpContextUser / IUser.cs

Blog.Core.Common / HttpContextUser / AspNetUser.cs

注入服务

services.AddScoped<IUser, AspNetUser>();

使用

构造函数注入:

 private readonly IUser _user;


 public ModuleController(IModuleServices moduleServices, IUser user)
 {
     _moduleServices = moduleServices;
     _user = user;
 }

直接使用:

 module.CreateId = _user.ID;
 module.CreateBy = _user.Name;

入门指南

前端项目

交流与反馈

  • FAQ page is a good place to see whether your question is already asked.
  • Ask a question in cnblogs if you need help.
  • Submit an issue if you found a bug or have a feature request.
  • Open a pull request when you prepared to contribute. Before that, it is encouraged to open an issue to discuss.

更新日志

Clone this wiki locally