Asp.net C # identity 3 layers - session replacement in VS 2017

1

Query, formerly when I was programming in asp.net form, I did it with sessions, now that I am working with asp.net mvc 5 in n layers, how can I get, for example, the ID or Full Name of the user logged in from any part of the application?

    
asked by Luis Vega 09.05.2018 в 07:24
source

2 answers

1

I understand that you use Identity to perform the login of your application so to access the name or id of the user who has logged in you have to use:

User.Identity.GetUserId()
User.Identity.GetUserName()
    
answered by 09.05.2018 в 11:49
0

You can apply data in a session using HttpContext . However, you must be careful with such implementations, the model view driver has no status. The session, however, will dictate some form of status.

You will have to account for that, otherwise you could enter a large number of orphaned session variables if they are not counted. Which could consume memory in your environment quickly depending on your application.

If the application is small, you can easily do so with the following in your Controller:

HttpContext.Current.Session.Add ("Título", "Datos");
    
answered by 09.05.2018 в 09:49