begin process at 2012 05 27 04:21:31
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

ASP.Net

 > ACCEDER AUX PROPRIÉTÉS DU PROFILE VIA UN EXPRESSIONBUILDER PERSONNALISÉ

ACCEDER AUX PROPRIÉTÉS DU PROFILE VIA UN EXPRESSIONBUILDER PERSONNALISÉ


 Information sur la source

Note :
9 / 10 - par 1 personne
9,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :ASP.Net Source .NET ( DotNet ) Classé sous :expressionbuilder, expression, profile, profileexpressionbuilder, dynamicexpressions Niveau :Débutant Date de création :14/12/2006 Date de mise à jour :14/12/2006 16:50:58 Vu / téléchargé :8 455 / 104

Auteur : jesusonline

Ecrire un message privé
Site perso
Ce membre participe au partage de revenus publicitaires
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note


 Description

ASP.net 2.0 permet de se servir des dynamics expressions dans notre code ASP.net .aspx, les dynamic expressions sont les <%$ AppSettings : mykey %> que l'on peut aussi appeller $-expression. Cet exemple montre comment créer nos propres $-expressions pour lire facilement les propriété contenu dans le Profile de l'utilisateur.

Pour l'utiliser il suffit de mettre la classe ci-dessus dans le dossier App_Code enregistrer l'expression dans le web.config :    

    <compilation>
      <expressionBuilders>
        <add expressionPrefix="Profile" type="ProfileExpressionBuilder"/>
      </expressionBuilders>
    </compilation>

vous pouvez alors utiliser l'expression de cette façon :

<asp:Label ID="lbl1" runat="server" Text="<%$ Profile:City %>"></asp:Label>

Ce code est une adaptation du livre "Programming ASP.net 2.0 Applciation - advanced Topics" de Dino Esposito.

Source

  • using System;
  • using System.Data;
  • using System.Configuration;
  • using System.Web;
  • using System.Web.Security;
  • using System.Web.Compilation;
  • using System.CodeDom;
  • using System.Web.UI;
  • [ExpressionPrefix("Profile")]
  • public class ProfileExpressionBuilder : ExpressionBuilder
  • {
  • /// <summary>
  • /// When overridden in a derived class, returns an object that represents the parsed expression.
  • /// </summary>
  • /// <param name="expression">The value of the declarative expression.</param>
  • /// <param name="propertyType">The type of the property bound to by the expression.</param>
  • /// <param name="context">Contextual information for the evaluation of the expression.</param>
  • /// <returns>
  • /// An <see cref="T:System.Object"></see> containing the parsed representation of the expression; otherwise, null if <see cref="M:System.Web.Compilation.ExpressionBuilder.ParseExpression(System.String,System.Type,System.Web.Compilation.ExpressionBuilderContext)"></see> is not implemented.
  • /// </returns>
  • public override object ParseExpression(string expression, Type propertyType, ExpressionBuilderContext context)
  • {
  • return expression;
  • }
  • /// <summary>
  • /// When overridden in a derived class, returns code that is used during page execution to obtain the evaluated expression.
  • /// </summary>
  • /// <param name="entry">The object that represents information about the property bound to by the expression.</param>
  • /// <param name="parsedData">The object containing parsed data as returned by <see cref="M:System.Web.Compilation.ExpressionBuilder.ParseExpression(System.String,System.Type,System.Web.Compilation.ExpressionBuilderContext)"></see>.</param>
  • /// <param name="context">Contextual information for the evaluation of the expression.</param>
  • /// <returns>
  • /// A <see cref="T:System.CodeDom.CodeExpression"></see> that is used for property assignment.
  • /// </returns>
  • public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
  • {
  • String propertyName = (String)parsedData;
  • CodePrimitiveExpression prim = new CodePrimitiveExpression(propertyName);
  • CodeExpression[] args = new CodeExpression[1] { prim };
  • CodeTypeReferenceExpression refType = new CodeTypeReferenceExpression(base.GetType());
  • return new CodeMethodInvokeExpression(refType, "GetProperty", args);
  • }
  • /// <summary>
  • /// Gets the value of the specified Profile Property.
  • /// </summary>
  • /// <param name="propertyName">Name of the Profile property.</param>
  • /// <returns></returns>
  • public static Object GetProperty(String propertyName)
  • {
  • return HttpContext.Current.Profile.GetPropertyValue( propertyName);
  • }
  • /// <summary>
  • /// When overridden in a derived class, returns an object that represents an evaluated expression.
  • /// </summary>
  • /// <param name="target">The object containing the expression.</param>
  • /// <param name="entry">The object that represents information about the property bound to by the expression.</param>
  • /// <param name="parsedData">The object containing parsed data as returned by <see cref="M:System.Web.Compilation.ExpressionBuilder.ParseExpression(System.String,System.Type,System.Web.Compilation.ExpressionBuilderContext)"></see>.</param>
  • /// <param name="context">Contextual information for the evaluation of the expression.</param>
  • /// <returns>
  • /// An object that represents the evaluated expression; otherwise, null if the inheritor does not implement <see cref="M:System.Web.Compilation.ExpressionBuilder.EvaluateExpression(System.Object,System.Web.UI.BoundPropertyEntry,System.Object,System.Web.Compilation.ExpressionBuilderContext)"></see>.
  • /// </returns>
  • public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
  • {
  • return GetProperty((String)parsedData);
  • }
  • /// <summary>
  • /// When overridden in a derived class, returns a value indicating whether the current <see cref="T:System.Web.Compilation.ExpressionBuilder"></see> object supports no-compile pages.
  • /// </summary>
  • /// <value></value>
  • /// <returns>true if the <see cref="T:System.Web.Compilation.ExpressionBuilder"></see> supports expression evaluation; otherwise, false.</returns>
  • public override bool SupportsEvaluate
  • {
  • get
  • {
  • return true;
  • }
  • }
  • }
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.Compilation;
using System.CodeDom;
using System.Web.UI;


[ExpressionPrefix("Profile")]
public class ProfileExpressionBuilder : ExpressionBuilder
{
    /// <summary>
    /// When overridden in a derived class, returns an object that represents the parsed expression.
    /// </summary>
    /// <param name="expression">The value of the declarative expression.</param>
    /// <param name="propertyType">The type of the property bound to by the expression.</param>
    /// <param name="context">Contextual information for the evaluation of the expression.</param>
    /// <returns>
    /// An <see cref="T:System.Object"></see> containing the parsed representation of the expression; otherwise, null if <see cref="M:System.Web.Compilation.ExpressionBuilder.ParseExpression(System.String,System.Type,System.Web.Compilation.ExpressionBuilderContext)"></see> is not implemented.
    /// </returns>
    public override object ParseExpression(string expression, Type propertyType, ExpressionBuilderContext context)
    {
        return expression;
    }

    /// <summary>
    /// When overridden in a derived class, returns code that is used during page execution to obtain the evaluated expression.
    /// </summary>
    /// <param name="entry">The object that represents information about the property bound to by the expression.</param>
    /// <param name="parsedData">The object containing parsed data as returned by <see cref="M:System.Web.Compilation.ExpressionBuilder.ParseExpression(System.String,System.Type,System.Web.Compilation.ExpressionBuilderContext)"></see>.</param>
    /// <param name="context">Contextual information for the evaluation of the expression.</param>
    /// <returns>
    /// A <see cref="T:System.CodeDom.CodeExpression"></see> that is used for property assignment.
    /// </returns>
    public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
    {

        String propertyName = (String)parsedData;
        CodePrimitiveExpression prim = new CodePrimitiveExpression(propertyName);
        CodeExpression[] args = new CodeExpression[1] { prim };

        CodeTypeReferenceExpression refType = new CodeTypeReferenceExpression(base.GetType());
        return new CodeMethodInvokeExpression(refType, "GetProperty", args);

    }

    /// <summary>
    /// Gets the value of the specified Profile Property.
    /// </summary>
    /// <param name="propertyName">Name of the Profile property.</param>
    /// <returns></returns>
    public static Object GetProperty(String propertyName)
    {
        return HttpContext.Current.Profile.GetPropertyValue( propertyName);
    }

    /// <summary>
    /// When overridden in a derived class, returns an object that represents an evaluated expression.
    /// </summary>
    /// <param name="target">The object containing the expression.</param>
    /// <param name="entry">The object that represents information about the property bound to by the expression.</param>
    /// <param name="parsedData">The object containing parsed data as returned by <see cref="M:System.Web.Compilation.ExpressionBuilder.ParseExpression(System.String,System.Type,System.Web.Compilation.ExpressionBuilderContext)"></see>.</param>
    /// <param name="context">Contextual information for the evaluation of the expression.</param>
    /// <returns>
    /// An object that represents the evaluated expression; otherwise, null if the inheritor does not implement <see cref="M:System.Web.Compilation.ExpressionBuilder.EvaluateExpression(System.Object,System.Web.UI.BoundPropertyEntry,System.Object,System.Web.Compilation.ExpressionBuilderContext)"></see>.
    /// </returns>
    public override object EvaluateExpression(object target, BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
    {
        return GetProperty((String)parsedData); 
    }

    /// <summary>
    /// When overridden in a derived class, returns a value indicating whether the current <see cref="T:System.Web.Compilation.ExpressionBuilder"></see> object supports no-compile pages.
    /// </summary>
    /// <value></value>
    /// <returns>true if the <see cref="T:System.Web.Compilation.ExpressionBuilder"></see> supports expression evaluation; otherwise, false.</returns>
    public override bool SupportsEvaluate
    {
        get
        {
            return true; 
        }
    }
}


 Conclusion

Vous pouvez trouver d'avantages d'informations sur le sujet sur mon blog : http://blogs.codes-sources.com/cyril/archive/2006/ 12/14/dynamic-expression-personnalise-profileexpre ssionbuilder-avec-asp-net-2-0.aspx


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Historique

14 décembre 2006 16:50:58 :
rajout de l'adresse du post de mon blog :-)

 Sources du même auteur

Source avec Zip Source .NET (Dotnet) UTILISATION DE LA MÉTHODE SORT ET SORTDIRECTION AVEC UN GRID...
Source .NET (Dotnet) RESPONSE.FILTER : MANIPULATION DU STREAM DE SORTIE ASP.NET
Source avec Zip Source .NET (Dotnet) OPTIMISATION DE LA SERIALISATION JSON POUR LES LIST<T>
Source avec Zip Source .NET (Dotnet) CRAWLABLELINKBUTTON : UPDATEPANEL ET RÉFÉRENCEMENT
Source .NET (Dotnet) POSTBACKCONTROL - COMMUNICATION CLIENT/SERVEUR AVEC LES UPDA...

 Sources de la même categorie

Source avec Zip Source .NET (Dotnet) GUESTBOOK AVEC GRIDVIEW par DanMor498
Source avec Zip CHECKED DROPDOWNLIST par fredzool
Source avec Zip Source avec une capture Source .NET (Dotnet) GRIDVIEW WITH TREEVIEW AND CALLBACK par fredzool
Source avec Zip APPELLER UN WEBSERVICE DEPUIS JAVASCRIPT par fredzool
Source avec Zip Source .NET (Dotnet) MONEY TEXTBOX WITH EMBEDED JAVASCRIPT par fredzool

 Sources en rapport avec celle ci

FONCTION SUPPRIMANT LES TAGS SGML AVEC LES EXPRESSIONS RÉGUL... par garfield90
[REGEXP]TESTER LA VALIDITÉ D'UNE DATE par vbtom
[REGEXP]TESTER LA VALIDITÉ D'UN E-MAIL par vbtom

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Pb sur RegEx [ par Djero ] salut à tous, je cherche à remplacer une expression dans une chaine de caractère via RegExp. set regEx = New RegExp regEx.IgnoreCase = True r Pb d'expression régulière [ par totodude ] Bonjour tout le monde,je voudrais remplacer dans du code html&lt;code&gt;&lt;/td&gt;&lt;td&gt; &lt;span id="toto" style="width:584px;"&gt;titi&lt expression reguliere [ par detoo ] Bonjour à tous!Je fais appel à vous pour une petite galère:ayant réaliser un moteur de recherche en asp avec des expressions régulières, je cherche un Remplacer la derniere "," (virgule) d'une expression ? [ par scoubigee ] Lors d'une boucle asp je g&#233;n&#232;re cette expression : '10044','5022','10045','5022,5',cette chaine sert a etre transmise a une fonction javascr est ce que cette expression est correcte? si non comment je peux la corriger? [ par firas_tn ] if ((Session["fonction"].ToString() != "LL") &amp; (Session["fonction"].ToString() != "planification") &amp; (Session["fonction"].ToString() != "accep Expression réguliere pour reconnaitre un entier positif? [ par fr64 ] Bonjour, Je cherche la syntaxe pour une expression r&#233;guli&#232;re qui permette valider qu'un texte saisi est un entier &gt; 0. Mon probl&#232;me Les maillons... [ par AbriBus ] Salut a tous,il existe en java un objet StingTokenizer qui permet de "decouper" une expression en fonction d'une autre expression... l'exemple le plus Profile mais pas dans l'utilisateur courant [ par gstrit ] Bonjour,J'utilise le createuserwizard pour cr&#233;er mes utilisateurs. J'ai ajout&#233;&nbsp;des champs nom et pr&#233;nom. Le probleme est que quand Comment ajouter des "property" à un "profile" d'utilisateur [ par SuperBouly ] Bonjour, Je travaille sur VS 2005 en VB, et j'utilise la sécurité du framawork 2.0.J'ai besoin qu'un utilisateur-adhérent soit repéré par d'autres par Expression Régulière [ par nounours21_6 ] Bonjour tout le monde,j'ai un petit sousis d'exp. reg. qui ne fonctionne pasvoila mon code :ElseIf Regex.IsMatch(Me<font size=


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,718 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales