Click here to Skip to main content
13,511,635 members
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 15 Dec 2009

Silverlight Windows User Identity Name

, 15 Dec 2009
Rate this:
Please Sign up or sign in to vote.
How to get the Windows user identity name in Silverlight.


This article explains how to get the Window User Identity Name in Silverlight without using WCF.


I was looking for Windows Authentication for Silverlight on the web. After Binging and Googling for a while, I found most of them use a WCF service to do the Windows authentication, where the primary objective is to just get the current user name. I thought using WCF for just getting the Windows user is kind of overkill, and moreover, you have to configure your basicHttpBinding to incorporate Windows authentication with WCF, which is kind of trivial, but can turn painful if not configured properly.

Below are three quick and easy steps to achieve the objective:

  1. Open the ASPX page that carries the Silverlight XAP file inside the Object tag and add a new param (let's call it Initparams):
  2. <param name="Initparams" 
      value="UserAccount=<%=HttpContext.Current.User.Identity.Name%>" />
  3. Open the App.xaml.cs file and declare a global variable:
  4. public static string UserID = string.Empty;

    To the application_startup method in App.xaml.cs, assign the param value to the global variable (this should be before the RootVisual statement):

    UserID = e.InitParams["UserAccount"];
  5. Declare a variable in your Mainpage.xaml or the navigation page, and assign the global variable value to the local variable, and you have the current logged on Windows user name.
  6. string UserAccount = App.UserID;


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

South Africa South Africa
Sivakumar Ramakrishnan

Interest : Programming, Reading, Music, Blogging

You may also be interested in...


Comments and Discussions

Questione.InitParams.Count = 0 Pin
chrisndirangu27-Sep-12 3:49
memberchrisndirangu27-Sep-12 3:49 
QuestionNot working within SharePoint environment Pin
Khaniya5-Sep-11 18:20
memberKhaniya5-Sep-11 18:20 
QuestionDoes not work when hosted on IIS Pin
nilesh.dt20-Apr-11 2:16
membernilesh.dt20-Apr-11 2:16 
AnswerRe: Does not work when hosted on IIS Pin
BrentLak17-Jan-12 3:53
memberBrentLak17-Jan-12 3:53 
GeneralRe: Does not work when hosted on IIS Pin
Member 38698188-Aug-12 1:05
memberMember 38698188-Aug-12 1:05 
GeneralRe: Does not work when hosted on IIS Pin
Member 965682710-Jul-13 8:21
memberMember 965682710-Jul-13 8:21 
GeneralMy vote of 5 Pin
Marcio_Coelho15-Mar-11 12:23
memberMarcio_Coelho15-Mar-11 12:23 
GeneralMy vote of 5 Pin
edgardanielcc14-Jan-11 12:24
memberedgardanielcc14-Jan-11 12:24 
QuestionCan be hacked Pin
douglampe4-Aug-10 3:35
memberdouglampe4-Aug-10 3:35 
GeneralMy vote of 5 Pin
Brad McBride8-Jul-10 10:07
memberBrad McBride8-Jul-10 10:07 
GeneralUser Machine Name Pin
rahulreddysandadi23-Jun-10 5:52
memberrahulreddysandadi23-Jun-10 5:52 
GeneralNot successful... Pin
clarkyip25-Apr-10 16:15
memberclarkyip25-Apr-10 16:15 
GeneralRe: Not successful... Pin
Webplethora25-Apr-10 19:29
memberWebplethora25-Apr-10 19:29 
GeneralRe: Not successful... Pin
clarkyip5-May-10 23:58
memberclarkyip5-May-10 23:58 
GeneralNice! Pin
madeinjapan10-Mar-10 3:41
membermadeinjapan10-Mar-10 3:41 
GeneralWorks for me Pin
jackmos4-Mar-10 5:16
memberjackmos4-Mar-10 5:16 
GeneralI am getting error on running the project Pin
jay.407.net26-Jan-10 0:02
memberjay.407.net26-Jan-10 0:02 
GeneralRe: I am getting error on running the project Pin
Webplethora26-Jan-10 20:28
memberWebplethora26-Jan-10 20:28 
GeneralRe: I am getting error on running the project Pin
nyssan5-Oct-10 1:11
membernyssan5-Oct-10 1:11 
GeneralGreat Pin
robalexclark14-Jan-10 23:03
memberrobalexclark14-Jan-10 23:03 
GeneralRe: Great Pin
Webplethora15-Jan-10 4:30
memberWebplethora15-Jan-10 4:30 
GeneralWell... Pin
Dewey15-Dec-09 23:01
memberDewey15-Dec-09 23:01 
GeneralRe: Well... Pin
Webplethora16-Dec-09 20:44
memberWebplethora16-Dec-09 20:44 
Generalthis is not article Pin
martyn_mcfly15-Dec-09 7:53
membermartyn_mcfly15-Dec-09 7:53 
GeneralRe: this is not article Pin
Morten Maate15-Dec-09 21:04
memberMorten Maate15-Dec-09 21:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180417.1 | Last Updated 15 Dec 2009
Article Copyright 2009 by Webplethora
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid