Ghita Lakhssassi
Ghita Lakhssassi

Reputation: 11

Show some informations about a current user

Well here I'm trying to build a web application with ASP.NET MVC, in terms of the interaction with the database I use ENTITY Framework and i'm using forms authentication too, i would like to show the username of my current user and the name of the agency where he works here are my two classes user :

public partial class UTILISATEUR
{
    public UTILISATEUR()
    {
        this.STATUT_DEMANDE = new HashSet<STATUT_DEMANDE>();
        this.LISTE_NOIR = new HashSet<LISTE_NOIR>();
    }

    public short ID_USER { get; set; }
    public short ID_AGENCE_APPARTENIR { get; set; }
    public string IDENTIFIANT { get; set; }
    public string MDP { get; set; }
    public string ROLE { get; set; }

    public virtual AGENCE AGENCE { get; set; }
    public virtual ICollection<STATUT_DEMANDE> STATUT_DEMANDE { get; set; }
    public virtual ICollection<LISTE_NOIR> LISTE_NOIR { get; set; }
}

} and Agency :

public partial class AGENCE
{
    public AGENCE()
    {
        this.DEMANDE_CRÉDIT = new HashSet<DEMANDE_CRÉDIT>();
        this.UTILISATEUR = new HashSet<UTILISATEUR>();
    }

    public short ID_AGENCE { get; set; }
    public string CODE_AGENCE { get; set; }
    public string ADRESSE { get; set; }
    public string NOM_AGENCE { get; set; }

    public virtual ICollection<DEMANDE_CRÉDIT> DEMANDE_CRÉDIT { get; set; }
    public virtual ICollection<UTILISATEUR> UTILISATEUR { get; set; }
}

}

in order to show the username of my current user i used this :

<%:HttpContext.Current.User.Identity.Name %>

but I can't find how to also display the name of the agency where the current user works, if anyone can help me please, I'm still a beginner XD Thanks in advance

Upvotes: 1

Views: 39

Answers (1)

Damiano C.
Damiano C.

Reputation: 282

In MVC applications you have to use Razor syntax. Razor code blocks are enclosed in @{ ... }

Try:

@User.Identity.Name

Here you can learn more about it:

Introduction to ASP.NET Web Programming Using the Razor Syntax (C#)

Upvotes: 2

Related Questions