Write form data in session

3

I created an access form for my administrative area, using a tutorial from Microsoft .

Now I need to retrieve the login that he typed to enter and show it on an admin page, and also to make future queries to the database.

How can I do this? I was told to save the login and password in one session and then retrieve it on the other page, but I have no idea how to implement it.

    
asked by anonymous 04.03.2014 / 01:48

2 answers

3

When you are using FormsAuthentication you can recover the logged in user as follows:

string username = "";
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
    username = HttpContext.Current.User.Identity.Name;
}
    
04.03.2014 / 11:16
4

Sessions are ways to store data that will be deleted when a particular event occurs (in the default ASP.NET behavior, when 20 minutes have elapsed since the last user action, or when the browser window is closed). >

Creating a session could not be easier:

Session["NomeDaSession"] = "ValorDaSession";

Check the value of it too:

// Primeiro verificamos se a session existe
if (Session["NomeDaSession"] != null)
    // Operações pertinentes

However, in addition to answering your question, it's up to me to recommend using a newer technology, if you're working on something new . I know that for legacy, there is usually no way. Instead of Web Forms, you should try to use ASP.NET MVC when appropriate.

    
04.03.2014 / 07:55