Click here to Skip to main content
Click here to Skip to main content

Silverlight Windows User Identity Name

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

Introduction

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

Background

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;

License

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

Share

About the Author

Webplethora

South Africa South Africa
Sivakumar Ramakrishnan
 
Interest : Programming, Reading, Music, Blogging

Comments and Discussions

 
Questione.InitParams.Count = 0 Pinmemberchrisndirangu27-Sep-12 4:49 
QuestionNot working within SharePoint environment PinmemberKhaniya5-Sep-11 19:20 
QuestionDoes not work when hosted on IIS Pinmembernilesh.dt20-Apr-11 3:16 
AnswerRe: Does not work when hosted on IIS PinmemberBrentLak17-Jan-12 4:53 
GeneralRe: Does not work when hosted on IIS PinmemberMember 38698188-Aug-12 2:05 
GeneralRe: Does not work when hosted on IIS PinmemberMember 965682710-Jul-13 9:21 
GeneralMy vote of 5 PinmemberMarcio_Coelho15-Mar-11 13:23 
GeneralMy vote of 5 Pinmemberedgardanielcc14-Jan-11 13:24 
QuestionCan be hacked Pinmemberdouglampe4-Aug-10 4:35 
GeneralMy vote of 5 PinmemberBrad McBride8-Jul-10 11:07 
GeneralUser Machine Name Pinmemberrahulreddysandadi23-Jun-10 6:52 
GeneralNot successful... Pinmemberclarkyip25-Apr-10 17:15 
GeneralRe: Not successful... PinmemberWebplethora25-Apr-10 20:29 
GeneralRe: Not successful... Pinmemberclarkyip6-May-10 0:58 
GeneralNice! Pinmembermadeinjapan10-Mar-10 4:41 
GeneralWorks for me Pinmemberjackmos4-Mar-10 6:16 
GeneralI am getting error on running the project Pinmemberjay.407.net26-Jan-10 1:02 
GeneralRe: I am getting error on running the project PinmemberWebplethora26-Jan-10 21:28 
GeneralRe: I am getting error on running the project Pinmembernyssan5-Oct-10 2:11 
GeneralGreat Pinmemberrobalexclark15-Jan-10 0:03 
GeneralRe: Great PinmemberWebplethora15-Jan-10 5:30 
GeneralWell... PinmemberDewey16-Dec-09 0:01 
GeneralRe: Well... PinmemberWebplethora16-Dec-09 21:44 
Generalthis is not article Pinmembermartyn_mcfly15-Dec-09 8:53 
GeneralRe: this is not article PinmemberMorten Maate15-Dec-09 22:04 
GeneralRe: this is not article PinmemberWebplethora16-Dec-09 21:46 
GeneralThanks! Pinmembermabinsay15-Dec-09 8:12 
GeneralRe: Thanks! Pinmemberibalthasar15-Dec-09 9:53 
GeneralRe: Thanks! PinmemberWebplethora16-Dec-09 21:45 
GeneralRe: Thanks! PinmemberWebplethora16-Dec-09 21:47 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141220.1 | Last Updated 15 Dec 2009
Article Copyright 2009 by Webplethora
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid