简体   繁体   中英

Respository and Identity in asp.Net MVC 5

The User property (type IPrincipal ) of a controller comes from the base Controller class. I would like to use a repository to keep as much of my code as possible out of my controller, and also aid testing. Since my repository doesn't inherit from Controller , how can I get the User information in my repository methods without passing it in?

I ended up using this

    private IPrincipal CurrentUser
    {
        get
        {
            return HttpContext.Current.User;
        }
    }

and all is well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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