Click here to Skip to main content
14,329,594 members

Silverlight Windows User Identity Name

Rate this:
5.00 (14 votes)
Please Sign up or sign in to vote.
5.00 (14 votes)
15 Dec 2009CPOL
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

 
GeneralRe: this is not article Pin
Webplethora16-Dec-09 20:46
memberWebplethora16-Dec-09 20:46 
GeneralThanks! Pin
mabinsay15-Dec-09 7:12
membermabinsay15-Dec-09 7:12 
GeneralRe: Thanks! Pin
ibalthasar15-Dec-09 8:53
memberibalthasar15-Dec-09 8:53 
GeneralRe: Thanks! Pin
Webplethora16-Dec-09 20:45
memberWebplethora16-Dec-09 20:45 
GeneralRe: Thanks! Pin
Webplethora16-Dec-09 20:47
memberWebplethora16-Dec-09 20:47 

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.

Article
Posted 15 Dec 2009

Stats

87.7K views
1.2K downloads
23 bookmarked