Profile ASP.Net Tutorial

File: Web.Config


  
  
  
    
              name="numberOfVisits"
        type="Int32"
        defaultValue="0"
        allowAnonymous="true" />
    

  



File: Default.aspx
<%@ Page Language="C#" %>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    void Page_PreRender() {
        lblUserName.Text = Profile.UserName;
        lblIsAnonymous.Text = Profile.IsAnonymous.ToString();
        Profile.numberOfVisits++;
        lblNumberOfVisits.Text = Profile.numberOfVisits.ToString();
    }
    protected void btnLogin_Click(object sender, EventArgs e) {
       FormsAuthentication.SetAuthCookie("Bob", false);
       Response.Redirect(Request.Path);
    }
    protected void btnLogout_Click(object sender, EventArgs e)
    {
        FormsAuthentication.SignOut();
        Response.Redirect(Request.Path);
    }



    Show Anonymous Identification


    
    

    User Name:
            id="lblUserName"
        Runat="server" />
    
    Is Anonymous:
            id="lblIsAnonymous"
        Runat="server" />
    
    Number Of Visits:
            id="lblNumberOfVisits"
        Runat="server" />
    
            id="btnReload"
        Text="Reload"
        Runat="server" />
            id="btnLogin"
        Text="Login"
        OnClick="btnLogin_Click"
        Runat="server" />
            id="btnLogout"
        Text="Logout"
        OnClick="btnLogout_Click"
        Runat="server" />