我的SL应用使用windowes身份验证。
当应用程序启动时,下面的代码将用户信息添加到colloection:
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获取用户信息?
发布于 2010-07-30 01:24:40
典型的模式是在上下文类型中包含一个名为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();发布于 2010-11-11 07:38:57
我认为在Application_Startup中你需要做一个LoadUser:
WebContext.Current.Authentication.LoadUser();
虽然我有一个类似的问题,让用户加载。但我使用的是表单身份验证。如果您创建了一个Silverlight Business Application并查看app.xaml.cs,您可以看到一个如何执行此操作的示例。
让我知道它是否适用于你的windows auth。
https://stackoverflow.com/questions/3364514
复制相似问题