New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

The Community Blog is a personal opinion of community members and by no means the official standpoint of DNN Corp or DNN Platform. This is a place to express personal thoughts about DNNPlatform, the community and its ecosystem. Do you have useful information that you would like to share with the DNN Community in a featured article or blog? If so, please contact .

The use of the Community Blog is covered by our Community Blog Guidelines - please read before commenting or posting.

Logging in to DotNetNuke from a Silverlight Application with RIA Authentication

This post will show you how to create a custom RIA Authentication system that will use DotNetNuke as the store for the users we can log in as.  DotNetNuke will also be used to host the Silverlight application so we need to make a few changes to the way you normally build a Silverlight Navigation Application.  So lets get started:

  • You will need a running instance of DNN to host the application so set one of those up.
  • Create a new Silverlight Business Application and call it “DNNRIA”.
  • Next add a new Web Application project and call it SilverlightShell, this will be the hosting module for the Silverlight application.
  • Remove the Default.aspx page and add a new user control called Shell.ascx.
  • Add a new folder called Dependencies and copy in the DotNetNuke.dll from your running instance of DNN and add a reference to it.
  • Now modify the Shell.ascx.cs file so it inherits from PortalModuleBase in the DotNetNuke.dll like so
    namespace SilverlightShell
        public partial class Shell : PortalModuleBase
  • Add a new Class Library – a normal one not a Silverlight one – to the solution and call it AuthenticationServices.  This where we will add our custom authentication code.
  • If you have a look in the web application added when you created the Silverlight Business Application you will see three classes.  Since we need these to be loaded with DNN copy them to the new AuthenticationServices project and change the name spaces to AuthenticationServices.
  • You will now need to add references to:
    • System.ComponentModel.DataAnnotations – make sure you choose the SDK version
    • System.Web
    • System.Web.DomainServices
    • System.Web.Ria
    • DotNetNuke – create a dependencies folder and reference it from there.
  • You should be able to build the class library now
  • In the DNNRIA.Web add a reference to the AuthenticationServices project and delete the files under the Services folder.
  • Now build your solution.


So by now we have a a place to put our custom Authentication code and a Silverlight app to call it with.  What we need to do now is get all of this into our DNN app.  To do this use an after build operation to copy the relevant files over to the target web site.  To do this we will edit the proj files for each of the projects as follows:

  • Right click the AuthenticationServices project and select Unload Project.
  • Then right click it again and select Edit, this will show you the MSBuild file for your project.
  • Now scroll down until you can see the
    <Target Name="AfterBuild" DependsOnTargets="DeployModule">
        <DNNDirectory>Physical path to the root of your portalDNNDirectory>
      <Target Name="DeployModule">
        <CreateItem Include="$(MSBuildProjectDirectory)\$(OutputPath)\*.dll">
          <Output TaskParameter="Include" ItemName="ModuleAssemblies" />
        <CreateItem Include="$(MSBuildProjectDirectory)\$(OutputPath)\*.pdb">
          <Output TaskParameter="Include" ItemName="ModuleDebug" />
        <Copy SourceFiles="@(ModuleAssemblies);@(ModuleDebug)" DestinationFolder="$(DNNDirectory)\bin" />
  • Now do the same thing for the DNNRIA Silverlight app and paste the following in
      <Target Name="AfterBuild" DependsOnTargets="DeployModule" Condition=" '$(IsDesktopBuild)'!='false' ">
        <DNNDirectory>Physical path to the portal rootlDNNDirectory>
      <Target Name="DeployModule">
        <CreateItem Include="$(MSBuildProjectDirectory)\$(OutputPath)\*.xap">
          <Output TaskParameter="Include" ItemName="ModuleXap" />
        <CreateItem Include="$(MSBuildProjectDirectory)\$(OutputPath)\*.dll">
          <Output TaskParameter="Include" ItemName="ModuleAssemblies" />
        <CreateItem Include="$(MSBuildProjectDirectory)\$(OutputPath)\*.pdb">
          <Output TaskParameter="Include" ItemName="ModuleDebug" />
        <Copy SourceFiles="@(ModuleAssemblies);@(ModuleDebug);@(ModuleXap)" DestinationFolder="$(DNNDirectory)\ClientBin" />
  • The last project we need to do this for is the DNN Module so unload the SilverlightShell project and paste in the following
     <Target Name="AfterBuild" DependsOnTargets="DeployModule">
        <DNNDirectory>Physical path to the root of your portalDNNDirectory>
      <Target Name="DeployModule">
        <CreateItem Include="$(MSBuildProjectDirectory)\$(OutputPath)\*.dll">
          <Output TaskParameter="Include" ItemName="ModuleAssemblies" />
        <CreateItem Include="$(MSBuildProjectDirectory)\$(OutputPath)\*.pdb">
          <Output TaskParameter="Include" ItemName="ModuleDebug" />
        <Copy SourceFiles="@(Content)" DestinationFiles="@(Content -> '$(DNNDirectory)\DesktopModules\$(ModuleFolder)\%(Identity)')" SkipUnchangedFiles="true" />
        <Copy SourceFiles="@(ModuleAssemblies);@(ModuleDebug)" DestinationFolder="$(DNNDirectory)\bin" />
  • Change the web.config Build Action to none because we dont need this to be deployed to our portal.
  • Reload all your projects and then do a build. 
  • In the LoginWindow.xaml.cs file change the DNNRIA.Web using statement to AuthenticationServices.
  • Rebuild

Ok now you should have in the folder structure of your portal, the following:

  • AuthenticationServices.dll & AuthenticationServices.pdb in the bin folder.
  • SilverlightShell.dll & SilverlightShell.pdb in the bin folder
  • DNNRIA.xap, DNNRIA.dll & DNNRIA.pdb in the ClientBin folder
    the dll and pdb file are copied here so we can use Visual Studio to attach to the Silverlight process for debugging purposes
  • lastly there should be a folder under DesktopModules called SilverlightShell with the Shell.ascx file.

Register the DNN module as per normal now in your portal and add it to a page.  Nothing happens yet because we havent written any code!!

Lets add the Silverlight control to the ascx file

    <div id="silverlightControlHost" style="position:relative; width: 100%; height: 400px; vertical-align:top; z-index:50;">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
          <param name="source" value="../../../../ClientBin/DNNRIA.xap"/>
          <param name="onError" value="onSilverlightError" />
          <param name="background" value="white" />
          <param name="minRuntimeVersion" value="3.0.40624.0" />
          <param name="autoUpgrade" value="true" />
          <a href="" style="text-decoration:none">
               <img src="" alt="Get Microsoft Silverlight" style="border-style:none"/>
        <iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px">iframe>

Build the solution again and refresh your page on the portal and you will see the standard Silverlight Business App. 

Note: Make sure you set the browser to Always Refresh from Server with the Developer Tools


Whew!  We are finally setup to have a look at the RIA Authentication stuff.


Look in the AuthenticationService.cs file down the bottom and you will see a class for User.  Modify it as below

    public class User : UserBase
        public int AffiliateID { get; set; }
        public string DisplayName { get; set; }
        public string Email { get; set; }
        public string FirstName { get; set; }
        public bool IsDeleted { get; set; }

This will be the object that we will return when the user logs in.

Next set a private variable and over ride the GetAuthenticatedUser method

        private User _user;
        protected override User GetAuthenticatedUser(System.Security.Principal.IPrincipal principal)
            return _user;

Now for some DotNetNuke magic.  Over ride the ValidateUser method as follows

       protected override bool ValidateUser(string userName, string password)
            var portalId = 0;
            var loginStatus = UserLoginStatus.LOGIN_FAILURE;
            var userInfo = UserController.ValidateUser(portalId, userName, password, "DNN", "", "My Web Portal", "", ref loginStatus);
            _user = new User()
                AffiliateID = userInfo.AffiliateID,
                DisplayName = userInfo.DisplayName,
                Email = userInfo.Email,
                FirstName = userInfo.FirstName,
                IsDeleted = userInfo.IsDeleted,
                Name = userInfo.DisplayName
            switch (loginStatus)
                case UserLoginStatus.LOGIN_FAILURE:
                    return false;
                    return true;

Make sure you change the portal name to the name of your portal.  I’ll use isolated storage later to store this but for now its hard coded, same for IP Address.

This code is now calling the DNN UserController class to validate the user and returning that user, then it updates the fields and returns true.  The GetAuthenticatedUser method then returns our custom user object back to the Silverlight Application as the RiaContext.Current.User!

A nice extra to this is it works just as well out of the browser!!

Bit of a long post but you get the idea.  You can download the code from here.


Comment Form

Only registered users may post comments.


Aderson Oliveira (22)
Alec Whittington (11)
Alessandra Daniels (3)
Alex Shirley (10)
Andrew Hoefling (3)
Andrew Nurse (30)
Andy Tryba (1)
Anthony Glenwright (5)
Antonio Chagoury (28)
Ash Prasad (37)
Ben Schmidt (1)
Benjamin Hermann (25)
Benoit Sarton (9)
Beth Firebaugh (12)
Bill Walker (36)
Bob Kruger (5)
Bogdan Litescu (1)
Brian Dukes (2)
Brice Snow (1)
Bruce Chapman (20)
Bryan Andrews (1)
cathal connolly (55)
Charles Nurse (163)
Chris Hammond (213)
Chris Paterra (55)
Clint Patterson (108)
Cuong Dang (21)
Daniel Bartholomew (2)
Daniel Mettler (181)
Daniel Valadas (48)
Dave Buckner (2)
David Poindexter (12)
David Rodriguez (3)
Dennis Shiao (1)
Doug Howell (11)
Erik van Ballegoij (30)
Ernst Peter Tamminga (80)
Francisco Perez Andres (17)
Geoff Barlow (12)
George Alatrash (12)
Gifford Watkins (3)
Gilles Le Pigocher (3)
Ian Robinson (7)
Israel Martinez (17)
Jan Blomquist (2)
Jan Jonas (3)
Jaspreet Bhatia (1)
Jenni Merrifield (6)
Joe Brinkman (274)
John Mitchell (1)
Jon Henning (14)
Jonathan Sheely (4)
Jordan Coopersmith (1)
Joseph Craig (2)
Kan Ma (1)
Keivan Beigi (3)
Kelly Ford (4)
Ken Grierson (10)
Kevin Schreiner (6)
Leigh Pointer (31)
Lorraine Young (60)
Malik Khan (1)
Matt Rutledge (2)
Matthias Schlomann (16)
Mauricio Márquez (5)
Michael Doxsey (7)
Michael Tobisch (3)
Michael Washington (202)
Miguel Gatmaytan (3)
Mike Horton (19)
Mitchel Sellers (40)
Nathan Rover (3)
Navin V Nagiah (14)
Néstor Sánchez (31)
Nik Kalyani (14)
Oliver Hine (1)
Patricio F. Salinas (1)
Patrick Ryan (1)
Peter Donker (54)
Philip Beadle (135)
Philipp Becker (4)
Richard Dumas (22)
Robert J Collins (5)
Roger Selwyn (8)
Ruben Lopez (1)
Ryan Martinez (1)
Sacha Trauwaen (1)
Salar Golestanian (4)
Sanjay Mehrotra (9)
Scott McCulloch (1)
Scott Schlesier (11)
Scott Wilkinson (3)
Scott Willhite (97)
Sebastian Leupold (80)
Shaun Walker (237)
Shawn Mehaffie (17)
Stefan Cullmann (12)
Stefan Kamphuis (12)
Steve Fabian (31)
Steven Fisher (1)
Tony Henrich (3)
Torsten Weggen (3)
Tycho de Waard (4)
Vicenç Masanas (27)
Vincent Nguyen (3)
Vitaly Kozadayev (6)
Will Morgenweck (40)
Will Strohl (180)
William Severance (5)
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out