0

Well,

I want to know how can i use the LoginView ASP, when i use my own method of Authentication, like in this topic.

Here follow the LoginView mark:

<asp:LoginView runat="server" ViewStateMode="Disabled">

    <AnonymousTemplate>
       <ul class="nav navbar-nav navbar-right">
            <li><a runat="server" href="~/Account/Register">Register</a></li>
            <li><a runat="server" href="~/Account/Login">Log in</a></li>
      </ul>
   </AnonymousTemplate>
    <LoggedInTemplate>

       <ul class="nav navbar-nav navbar-right">
            <li>
                <a runat="server" href="~/Account/Manage" title="Manage your account">Hello, <%: Context.User.Identity.GetUserName()  %> !</a>
             </li>
             <li>
                <asp:LoginStatus runat="server" LogoutAction="Redirect" LogoutText="Log   off" LogoutPageUrl="~/" OnLoggingOut="Unnamed_LoggingOut" />
             </li>
       </ul>

    </LoggedInTemplate>
</asp:LoginView>

This is my Authentication:

 //this is the button's event 

 protected void LogIn(object sender, EventArgs e)
 {
    try {

         // this is my method to get the user properties, case he exists 

          Usuario user = DUsuario.logar(Email.Text, Password.Text);

          if (user != null)
          {
             Session["user"] = user;
             Response.Redirect("~/Default.aspx");

          }else{

       //Rest of my code... 

  }

My class Usuario, with the user's data.

public class Usuario
{
    public int id { get; set; }
    public string login { get; set; }
    public string nome { get; set; }  
    public string senha { get; set; }
    public string email { get; set; }
    public DateTime ultimoAcesso { get; set; }
    public Mes mesAtual { get; set; }

}

My code is working using Session to log in , to Redirect to a Login page when the user is not logged in, i can access user's data... But i don't know, and i didn't find how to use the ListView in my case.

Following other topic, i tried to use follow method after get the user logged in informations, but it did't work:

FormsAuthentication.SetAuthCookie(user.nome, true);

Somebody could help ? '.'

Community
  • 1
  • 1

1 Answers1

0
FormsAuthentication.SetAuthCookie(user.nome, true);

should work (I use it a lot). I find I have to do a redirect back to my home page so that the cookie gets loaded and the page authenticates.

Peter Kellner
  • 14,748
  • 25
  • 102
  • 188