Click here to Skip to main content
Licence CPOL
First Posted 15 Dec 2009
Views 36,930
Downloads 583
Bookmarked 20 times

Silverlight Windows User Identity Name

By | 15 Dec 2009 | Article
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)

About the Author

Webplethora



South Africa South Africa

Member

Sivakumar Ramakrishnan
 
Interest : Programming, Reading, Music, Blogging

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionNot working within SharePoint environment PinmemberKhaniya18:20 5 Sep '11  
QuestionDoes not work when hosted on IIS Pinmembernilesh.dt2:16 20 Apr '11  
AnswerRe: Does not work when hosted on IIS PinmemberBrentLak3:53 17 Jan '12  
GeneralMy vote of 5 PinmemberMarcio_Coelho12:23 15 Mar '11  
GeneralMy vote of 5 Pinmemberedgardanielcc12:24 14 Jan '11  
QuestionCan be hacked Pinmemberdouglampe3:35 4 Aug '10  
GeneralMy vote of 5 PinmemberBrad McBride10:07 8 Jul '10  
GeneralUser Machine Name Pinmemberrahulreddysandadi5:52 23 Jun '10  
GeneralNot successful... Pinmemberclarkyip16:15 25 Apr '10  
GeneralRe: Not successful... PinmemberWebplethora19:29 25 Apr '10  
GeneralRe: Not successful... Pinmemberclarkyip23:58 5 May '10  
GeneralNice! Pinmembermadeinjapan3:41 10 Mar '10  
GeneralWorks for me Pinmemberjackmos5:16 4 Mar '10  
GeneralI am getting error on running the project Pinmemberjay.407.net0:02 26 Jan '10  
GeneralRe: I am getting error on running the project PinmemberWebplethora20:28 26 Jan '10  
GeneralRe: I am getting error on running the project Pinmembernyssan1:11 5 Oct '10  
GeneralGreat Pinmemberrobalexclark23:03 14 Jan '10  
GeneralRe: Great PinmemberWebplethora4:30 15 Jan '10  
GeneralWell... PinmemberDewey23:01 15 Dec '09  
GeneralRe: Well... PinmemberWebplethora20:44 16 Dec '09  
Generalthis is not article Pinmembermartyn_mcfly7:53 15 Dec '09  
GeneralRe: this is not article PinmemberMorten Maate21:04 15 Dec '09  
GeneralRe: this is not article PinmemberWebplethora20:46 16 Dec '09  
GeneralThanks! Pinmembermabinsay7:12 15 Dec '09  
GeneralRe: Thanks! Pinmemberibalthasar8:53 15 Dec '09  

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.

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