object session mvc 4 in razor

2

Good morning,

I have an AccountControler in my application, the AccountControler has the ActionResult to log in and disconnect.

Once the user is connected (user that is inside a table in sqlserver), I need to know how to obtain the data from different fields of that user.

Example (silly)

Pepito puts his name and password and enters correctly, but when entering I have to filter by the zip code where he lives, to see a list of its streets.

I think it works with the session object but I can not understand how it works or how to do it.

    
asked by Zarios 10.06.2016 в 14:12
source

1 answer

1

To use the session variables it is as easy as in your Login method to save what you need:

string codigoPostal = "XXXXX"; //Obtén la información que necesites
Session["CodigoPostal"]=codigoPostal;

And then access in any function what you have saved:

var codigoPostal=Session["CodigoPostal"] as string; //Fíjate que se tiene que hacer un cast con el as para poder acceder.
    
answered by 15.06.2016 / 15:07
source