Continuing with the series of Blackboard .NET Building Block posts, today I use the previous example to build upon in order to display the currently logged in user, and their details.
Pre-requiste: To complete this example, you’ll need 3 DLLs. Its been so long since I originally got them that I can’t remember their source location – I’m presuming there must be a .NET SDK Download link on Behind The Blackboard or Edugarage. The 3 DLLs required are namely:
1. Open the previous Hello World Example (short article here).
2. Right click on the website in the ‘Solution Explorer’ window and select ‘Add Reference…’ from the list.
3. Add the 3 Dlls mentioned in the pre-requiste. (Note: You probably only require the ‘BbPlatform.dll’ for this example, but out of laziness I tend to add all 3).
4. Returning to the website, open the Default.aspx and replace the ‘Hello World’ text with an asp:Label control, e.g.
<asp:Label ID="lblUserDetails" runat="server" />
5. Right click on the Default.aspx page, and select ‘View Code’ option.
6. In the code-behind page, locate the Page_Load method, and add the following code to output the current user’s username to the asp:Label.
lblUserDetails.Text = Blackboard.Platform.Session.GetCurrentSession().GetCurrentUser().UserName;
(Note: After typing the period after GetCurrentUser() you’ll see all the properties that you can retrieve about the current user)
7. Publish the website as before (hopefully the IDE has remembered the previous publish location).
8. Zip up the contents of the publish location and install the zip file to Blackboard.
Hopefully looking at this module in Blackboard will now display your username. Now would be a good time to play around with the other Blackboard properties and output those as well.
(One thing to note – my BB Test Server was unavailable at time of writing, so I was unable to fully test this – hopefully it works, give me a shout if it doesn’t).