Click here to Skip to main content
15,071,262 members
Articles / Programming Languages / C#
Posted 15 Dec 2009


23 bookmarked

Silverlight Windows User Identity Name

Rate me:
Please Sign up or sign in to vote.
5.00/5 (14 votes)
15 Dec 2009CPOL1 min read
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. XML
    <param name="Initparams" 
      value="UserAccount=<%=HttpContext.Current.User.Identity.Name%>" />
  3. Open the App.xaml.cs file and declare a global variable:
  4. C#
    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. C#
    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

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
professionalKhaniya5-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
professionaljackmos4-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
Artem S. Dmitriev15-Dec-09 7:53
MemberArtem S. Dmitriev15-Dec-09 7:53 
GeneralRe: this is not article Pin
Morten Holk Maate15-Dec-09 21:04
MemberMorten Holk 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.