Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Silverlight 如何从WebContext获取用户信息?_Silverlight_Silverlight 4.0 - Fatal编程技术网

Silverlight 如何从WebContext获取用户信息?

Silverlight 如何从WebContext获取用户信息?,silverlight,silverlight-4.0,Silverlight,Silverlight 4.0,我的SL应用程序使用windowes身份验证 应用程序启动时,以下代码将用户信息添加到ColloAction: public App() { InitializeComponent(); // Create a WebContext and add it to the ApplicationLifetimeObjects // collection. This will then be available as WebContext.

我的SL应用程序使用windowes身份验证

应用程序启动时,以下代码将用户信息添加到ColloAction:

 public App()
    {
        InitializeComponent();

        // Create a WebContext and add it to the ApplicationLifetimeObjects
        // collection.  This will then be available as WebContext.Current.

        WebContext webContext = new WebContext();
        webContext.Authentication = new WindowsAuthentication() { DomainContext = new AMSRIAServices.Web.AuthenticationContext() };
        this.ApplicationLifetimeObjects.Add(webContext);
    }

然后,在用户控件的任何代码隐藏中,我都希望返回用户信息。我试图使用WebContext.Current.User,但什么也没有得到。如何从代码中的Application.Current.ApplicationLifetimeObjects获取用户信息?

典型的模式是在上下文类型中包含一个名为
Current
的静态属性,然后在
StartService
方法中分配该属性

public class MyWebContext : IAppicationService
{

   public MyWebContext Current {get; private set}


   public void StartService(ApplicationServiceContext context)
   {
      Current = this;
      // Other initialisation code
   }
   // Rest of implementation

}
因此,访问webContext对象只需执行以下操作:-

MyWebContext.Current.DoStuff();

典型的模式是在上下文类型中包含一个名为
Current
的静态属性,然后在
StartService
方法中分配该属性

public class MyWebContext : IAppicationService
{

   public MyWebContext Current {get; private set}


   public void StartService(ApplicationServiceContext context)
   {
      Current = this;
      // Other initialisation code
   }
   // Rest of implementation

}
因此,访问webContext对象只需执行以下操作:-

MyWebContext.Current.DoStuff();

我认为在应用程序启动时,您需要执行LoadUser:

WebContext.Current.Authentication.LoadUser()

尽管我在让用户加载时遇到了类似的问题。但我用的是formsauthentication。如果您创建Silverlight业务应用程序并查看app.xaml.cs,您可以看到如何执行此操作的示例


让我知道它是否适用于windows auth。

我认为在应用程序启动时,您需要执行LoadUser:

WebContext.Current.Authentication.LoadUser()

尽管我在让用户加载时遇到了类似的问题。但我用的是formsauthentication。如果您创建Silverlight业务应用程序并查看app.xaml.cs,您可以看到如何执行此操作的示例


让我知道它是否适用于windows auth。

谢谢。我已经有了WebContext,并在应用程序起点中设置了它(请参阅文章,我添加了应用程序()。它可用于SL应用程序。我想知道如何获取它。@KentZhou:如果是这样,它将已经从WebContextBase派生出来,并且有一个
Current
属性。我对WCF RIA服务的了解还不够,不知道为什么用户还没有配置,可能是异步的,或者需要先登录。谢谢。我已经有了WebContext,并在应用程序起点中设置了它(请参阅文章,我添加了应用程序()。它可用于SL应用程序。我想知道如何获取它。@KentZhou:如果是这样,它将已经从WebContextBase派生出来,并且有一个
Current
属性。我对WCF RIA服务的了解还不够,不知道为什么用户还没有配置,可能是异步的,或者需要先登录。