如何在Silverlight 2.0中获取当前用户名

时间:2022-05-29 23:20:51

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...

大家好我正在用silverlight2.0制作一个asp.net项目。但我无法获得当前用户名...我怎样才能得到当前用户名谢谢...

3 个解决方案

#1


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.

1)使用ASP.NET Silverlight控件。加载服务器控件时,使用HttpContext.Current.User.Identity.Name获取当前用户名,并将其作为InitParam发送到silverlight控件中。

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

2)我回调服务器时通常只需要用户名。如果服务需要Windows身份验证,您只需在服务中调用HttpContext.Current.User.Identity.Name即可获取用户名

#2


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

基本上,您需要实现一项服务,该服务将当前用户信息返回给客户端,并在Silverlight应用程序启动时调用此服务。

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;
    }
}

#3


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

AFAIK不可能,但本文介绍了一些选项。看看这个。如果您使用的是表单身份验证,请查看此文章。

#1


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.

1)使用ASP.NET Silverlight控件。加载服务器控件时,使用HttpContext.Current.User.Identity.Name获取当前用户名,并将其作为InitParam发送到silverlight控件中。

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

2)我回调服务器时通常只需要用户名。如果服务需要Windows身份验证,您只需在服务中调用HttpContext.Current.User.Identity.Name即可获取用户名

#2


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

基本上,您需要实现一项服务,该服务将当前用户信息返回给客户端,并在Silverlight应用程序启动时调用此服务。

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;
    }
}

#3


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

AFAIK不可能,但本文介绍了一些选项。看看这个。如果您使用的是表单身份验证,请查看此文章。