2010-04-20 89 views

回答

3

此博客文章有答案。 Silverlight with WCF Ria Services and Active Directory Roles。感谢丹这篇文章!

我正在使用Silverlight 4,所以自从这篇文章发生了一些改变。我还为这个项目使用了业务应用程序模板。

第1步。这已经在App.xaml.cs代码后面的BussinessApplication模板中设置。您需要注释webContext.Authentication = new FormsAuthentication();,并取消注释行webContext.Authentication = new WindowsAuthentication();

第2步。没有变化。将<authentication mode="Windows"/>添加到/configuration/system.web元素下的web.config。

第3步。RiaContex现在是WebContext,因此请在示例中更改此内容。加载用户的第一行,RiaContext.Current.Authentication.LoadUser(this.Application_UserLoaded, null);已经在代码中。

第4步。没有变化。将<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"/>添加到/configuration/system.web元素下的web.config。

通过这些小的更改,Silverlight应用程序连接到Active Directory并填充了我正在寻找的WebContext.Current.User.Roles