Silverlight e Windows Login


In Sirverlight non esiste nativamente il modo per ottenere le informazioni sull’utente connesso a Windows. Quello che si può fare é utilizzare del codice ASP lato server e poi recuperare le informazioni da Silverlight.


Nel nostro container ASP che host il controllo Silverlight aggiungiamo qualcosa del tipo:


....
  
    void Page_Load()
    {
      this.UsernameField.Value = User.Identity.Name;
    }
  
  ...

Nel body invece mettiamo un controllo nascosto per contenere i nostri dati:


  ...
  
  ...

Lato Silverlight leggiamo, quando ci occorre, il volore del tag input:

public string GetUser()
{
  HtmlDocument doc = HtmlPage.Document;
  if (doc == null)
  {
    return string.Empty;
  }
  HtmlElement elm = doc.GetElementById("UserField");
  if (elm == null)
  {
    return string.Empty;
  }
  return elm.GetAttribute("value");
}

One thought on “Silverlight e Windows Login

  1. Pingback: Silverlight e Windows Login | B.Log

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s