Accessing HttpContext and User Identity from data layer

前端 未结 6 1978
Happy的楠姐
Happy的楠姐 2021-02-15 11:08

I need to implement AddedBy/ChangedBy type fields on my Base Entity that all other entities inherit from ( Fluent Nhibernate ).

Accessing HttpContext.User.Identity

6条回答
  •  长情又很酷
    2021-02-15 11:35

    1. HttpContext.User.Identity is of System.Security.Principal.IIdentity type. Don't mess it up with Microsoft.AspNet.Identity library (NuGet package) which is actually pointed by asp.net-identity tag in your question.

    2. Identity lib consists of common part and its ORM implementation. Typically it is for Entity Framework. But if you're going to use Microsoft.AspNet.Identity package in the way you describe with NHibernate, then you most likely will need this package.

    I didn't use it, but I used EF implementation. See this answer how to inherit of predefined IdentityDbContext where T is your User class. I guess, NH has similar fluent configuration. Then you can link any of entities in your DbContext to AppUser

提交回复
热议问题