views:

2436

answers:

3

Hi guys i m making one asp.net project with silverlight2.0 .But i cannot get current user name... how can i get current user name thanks...

A: 

AFAIK its not possible but this article shows some options. Check it out. If you are using forms authentication then check this article.

Shoban
+2  A: 

Basically you need to implement a service that will return current user info to the client and call this service on silverlight application startup.

The example of the service:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class UserInfoService : IUserInfoService
{
 public UserInfo GetUserInfo()
 {
  if (HttpContext.Current.User.Identity.IsAuthenticated)
   return null;

  var userInfo = new UserInfo
  {
   Login = HttpContext.Current.User.Identity.Name,
   Fullname = ...,
  };

  return userInfo;
 }
}

HTH

Alexander K.
+4  A: 

I basically handle this in one of two ways.

1) Use the ASP.NET Silverlight control. When the server control loads, grab the current user name using HttpContext.Current.User.Identity.Name and send it in as an InitParam into the silverlight control.

2) I generally only need the user name when I call back to the server. If the service requires windows authentication, you can just call HttpContext.Current.User.Identity.Name inside the service to get the user name

Jacob Adams