Dynamic is magic : A solution to use the ASP.NET profile in web applications.

Profiles are not auto generated with Web Applications, so you can’t just add them in the web.config and use them directly. (unless …)

The WebSite project do a magic thing : when you add properties to the profile in the web.config file, a class is autogenerated and allow the developer to access these properties. The web application project don’t do that.

You can find some workarounds over the web, here is some

The “dynamic” keyword help us here.

So, no more chit chat, here is the code snippets for a profile with 3 parameters : LastName, FirstName and GSM

web.config:


<profile enabled="true">
 <providers>
 <clear/>
 <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="MyApp"/>
 </providers>
 <properties>
 <add name="FirstName" type="string"/>
 <add name="LastName" type="string"/>
 <add name="GSM" type="string"/>
 </properties>
 </profile>

A “business” class, I called it “ProfilePresenter”, it returns the profile of the logged user and allow modifications:


public class ProfilePresenter
{
 public dynamic GetProfile()
 {
 return HttpContext.Current.Profile;
 }
 public dynamic UpdateProfile(string FirstName, string LastName, string GSM)
 {
 HttpContext.Current.Profile.SetPropertyValue("FirstName", FirstName);
 HttpContext.Current.Profile.SetPropertyValue("LastName", LastName);
 HttpContext.Current.Profile.SetPropertyValue("GSM", GSM);
 HttpContext.Current.Profile.Save();
 return HttpContext.Current.Profile;
 }
}

A page that uses the ProfilePresenter class : displaying the profile properties, and edit them

ObjectDataSource:


<asp:ObjectDataSource runat="server" ID="ProfileODS" TypeName="Board.Presenters.ProfilePresenter"
 SelectMethod="GetProfile" UpdateMethod="UpdateProfile"/>
<pre>

FormView: Display part

 <asp:FormView runat="server" ID="ProfileFV" DataSourceID="ProfileODS" RenderOuterTable="false">
 <EmptyDataTemplate>
 <p>
 No profil datas
 </p>
 </EmptyDataTemplate>
 <ItemTemplate>
 <h2>
 Profil informations</h2>
 <div>
 <asp:Button runat="server" ID="Edit" CommandName="Edit" Text="Edit" /></div>
 <table>
 <thead>
 <tr>
 <th colspan="2">
 Infos
 </th>
 </tr>
 </thead>
 <tbody>
 <tr>
 <th>
 LastName
 </th>
 <td>
 <%# Eval("LastName")%>
 </td>
 </tr>
 <tr>
 <th>
 FirstName
 </th>
 <td>
 <%# Eval("FirstName")%>
 </td>
 </tr>
 <tr>
 <th>
 GSM
 </th>
 <td>
 <%# Eval("GSM")%>
 </td>
 </tr>
 </tbody>
 </table>
 </ItemTemplate>

FormView : the Edit part

 <EditItemTemplate>
 <h2>
 Profil Update</h2>
 <div>
 <asp:Button runat="server" ID="Edit" CommandName="Cancel" Text="Annuler" />
 <asp:Button runat="server" ID="Button1" CommandName="Update" Text="Sauver" /></div>
 <table>
 <thead>
 <tr>
 <th colspan="2">
Infos
 </th>
 </tr>
 </thead>
 <tbody>
 <tr>
 <th>
 LastName
 </th>
 <td>
 <asp:TextBox runat="server" ID="LastName" Text='<%# Bind("LastName")%>' />
 </td>
 </tr>
 <tr>
 <th>
 FirstName
 </th>
 <td>
 <asp:TextBox runat="server" ID="FirstName" Text='<%# Bind("FirstName")%>' />
 </td>
 </tr>
 <tr>
 <th>
 GSM
 </th>
 <td>
 <asp:TextBox runat="server" ID="GSM" Text='<%# Bind("GSM")%>' />
 </td>
 </tr>
 </tbody>
 </table>
 </EditItemTemplate>
 </asp:FormView>

A simple use :


dynamic profil = HttpContext.Current.Profile;
if (profil != null)
{
 Console.Writeline(profil.GSM);
}

Another example : retrieve the gsm numbers from  members of a security role. It shows how to retrieve the profile of an other user


string[] users = Roles.GetUsersInRole(role);

List<string> gsm = new List<string>();
foreach (string user in users)
{
 dynamic profil = HttpContext.Current.Profile;
 dynamic profi = profil.GetProfile(user);
 if (profi != null)
 {
 if (!string.IsNullOrEmpty(profi.GSM))
 {
 gsm.Add(profi.GSM);
 }
 }
}

Let me know what you think !

jQuery Performance Tips And Tricks 2011 by Addy Osmani

Addy Osmani has made a nice video presentation about jQuery performance improvement.

jQuery Performance Tips And Tricks 2011 – Addy Osmani from Addy Osmani on Vimeo.

Incoming search terms:

  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1844 35T_b_Y8soGvo4xSAU1m8PjhmoYH-EL8gXWusRngLEHdFQMeOE0gURSS1C0yBk7e 6bb615bbcfdf0ab0af2e0c04c3dd63e3eb4b772c&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1837 AQIKsM1z-IIHRgrdSit6Oy9E-2794VsaBExgNXLHUHJ1zS1TM07INsgm3hDxh1hu f471aefb75ccd71430910741a93bb71303f4e605&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1835 VcuLx9YVKeBdGTjdj4ZYDScMdEkxTatyO9_oVYgX1nPKvKWqAX9FWJFaFnR1G9xw d244038e701ebed06c7939c06c0b44ca39ad6a82&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1834 ORJKY2WNn4HMx2iTDYeP2PeA8UxRPIisdwZKYUQDR-0xxYS3KYKE8XVrlpIAQbDn 88d05d43bef75d89e38b1d07bfd0d50da62c6869&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1832 O7hjo7T38VU-lVoZR9OZqxD3EFwNHJYzcyDA6OtQzjtXvgumst_pxVY_wAo2t3Qq 3fa15e09d7bfc872879f1baddee20b983ccac08d&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1829 NeEMXhn886lV1ejCZybPxODn1YBVJ36DVsnHdPkjh4zy3-ZqU9hVQyj36-8s-9Mc e710992026c328079b8b826130bdfa0e862ff42d&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1828 WicKFHJ2v0w4cnECslAbmPxnzB3EPZgbvwJliLSs4LhIRTuIRgxb3wVJHX_bKOiF c27c2aff8df3b8aa7b9d3efb1f67f76d2cea5766&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1827 jqieuuMeEDc7ck6nMJvWvBeMLgHr6whynSnQDlpGcLHARUp2IPYW5SzLLCGUconM cddfb93cb1f949556c7d172caa1d2da8315633ca&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1825 _IHpN_YPNsVHvQLlhFh7L2arpQovzvuSjQ12qT3Vh3mkzCH51QTO0I4CtqM8okGM 3749c36e72e01b72a50dea38bb3238dbcaca1fc4&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme
  • https://yandex ru/clck/jsredir?from=yandex ru;search;web;;&text=&etext=1823 -yE22dmHKbzfwvOsy7LgO_1aDkMVBYZEUDvHuQkIue6CJfD2BRFYnFqr0UTm2uJv aa17f3810abb2ffbbb0011ca25404f4815e096e5&uuid=&state=_BLhILn4SxNIvvL0W45KSic66uCIg23qh8iRG98qeIXme

How to set two background images for an HTML page ?

The other day I was wondering how could I set two background images for an HTML page and I came with one solution.
I don’t know if it’s the best way to do that but it worked as I wanted.

To explain the solution, here is the complete steps I made

First I had an HTML page without any background:

Beach_withoutBackground

Then I added some CSS to set a background image :

bg

body
{
   background:url("img/bg.gif") no-repeat fixed left top #9AE4E8;
}

The result was good :
Beach_OneBackground
But I wanted to add a second background image on the right bottom :
logobeachrahier_medium
So I moved my background declaration for the head part of the html file

html
{
 background:url("img/bg.gif") no-repeat fixed left top #9AE4E8;
}

and I added an other background declaration for the body part

body
{
 background:url("img/logobeachrahier_medium.png") no-repeat fixed right bottom ;
}

The background declared for the body is applied over the html one:

Beach_TwoBackground
I think it’s Pretty good now.

Incoming search terms:

  • html background gifs
  • how to set img in html
  • background gif img
  • background html repeat
  • background page html
  • two background images cover html
  • background-bg
  • bg background gif
  • bg gif
  • how to add multiple background in htmlpage

Change the Office 2010 product key

A few days ago I received Office 2010 from work.

I installed it with the provided product key, and tried to activate it:

image

image

Unfortunately, the product key has been already activated for the maximum number of times permitted.

image

So I asked for a new key, I received it and I tried to change the key

image

After several researches, I couldn’t find an option to change this key.

I finally tried to repair the installation, so I start the office installer

and  the wanted option was here :

image

Choose “Enter a product key” then click on Continue

image

Enter your product key and click on “Continue”.

Then you cant choose if you want to install additional office options

Now it’s activated !

image

Incoming search terms:

  • product key office 2010
  • office 2010 activate key
  • office 2010 activation by telephone
  • office 2010 activation telephone
  • office 2010 product key has been activated maximum times
  • office 2010key
  • your product key