Click here to Skip to main content
Licence CPOL
First Posted 15 Dec 2009
Views 32,517
Downloads 467
Bookmarked 19 times

Silverlight Windows User Identity Name

By Webplethora | 15 Dec 2009
How to get the Windows user identity name in Silverlight.

1

2
1 vote, 7.1%
3

4
13 votes, 92.9%
5
5.00/5 - 14 votes
1 removed
μ 4.81, σa 0.94 [?]

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 PinmemberKhaniya19:20 5 Sep '11  
QuestionDoes not work when hosted on IIS Pinmembernilesh.dt3:16 20 Apr '11  
AnswerRe: Does not work when hosted on IIS PinmemberBrentLak4:53 17 Jan '12  
GeneralMy vote of 5 PinmemberMarcio_Coelho13:23 15 Mar '11  
GeneralMy vote of 5 Pinmemberedgardanielcc13:24 14 Jan '11  
QuestionCan be hacked Pinmemberdouglampe4:35 4 Aug '10  
GeneralMy vote of 5 PinmemberBrad McBride11:07 8 Jul '10  
GeneralUser Machine Name Pinmemberrahulreddysandadi6:52 23 Jun '10  
GeneralNot successful... Pinmemberclarkyip17:15 25 Apr '10  
GeneralRe: Not successful... PinmemberWebplethora20:29 25 Apr '10  
GeneralRe: Not successful... Pinmemberclarkyip0:58 6 May '10  
GeneralNice! Pinmembermadeinjapan4:41 10 Mar '10  
GeneralWorks for me Pinmemberjackmos6:16 4 Mar '10  
GeneralI am getting error on running the project Pinmemberjay.407.net1:02 26 Jan '10  
GeneralRe: I am getting error on running the project PinmemberWebplethora21:28 26 Jan '10  
GeneralRe: I am getting error on running the project Pinmembernyssan2:11 5 Oct '10  
GeneralGreat Pinmemberrobalexclark0:03 15 Jan '10  
GeneralRe: Great PinmemberWebplethora5:30 15 Jan '10  
GeneralWell... PinmemberDewey0:01 16 Dec '09  
GeneralRe: Well... PinmemberWebplethora21:44 16 Dec '09  
Generalthis is not article Pinmembermartyn_mcfly8:53 15 Dec '09  
GeneralRe: this is not article PinmemberMorten Maate22:04 15 Dec '09  
GeneralRe: this is not article PinmemberWebplethora21:46 16 Dec '09  
GeneralThanks! Pinmembermabinsay8:12 15 Dec '09  
GeneralRe: Thanks! Pinmemberibalthasar9: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
Web02 | 2.5.120209.1 | Last Updated 15 Dec 2009
Article Copyright 2009 by Webplethora
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid