Silverlight业务应用程序Windows身份验证
问题描述:
我似乎无法让Windows身份验证在Silverlight业务应用程序中工作。Silverlight业务应用程序Windows身份验证
我已经作出所需的改变见下文
更改为Windows身份验证中的App.xaml
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 FormsAuthentication();
webContext.Authentication = new WindowsAuthentication();
this.ApplicationLifetimeObjects.Add(webContext);
}
在web.config中更改为Windows身份验证
<authentication mode="Windows"/>
<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"/>
我把一个断点在Application_UserLoaded事件但没有任何反应: -
private void Application_UserLoaded(LoadUserOperation operation)
{
foreach (var r in WebContext.Current.User.Roles)
{
//do something
}
}
任何人都可以提出什么问题。我根本没有对该项目做任何其他改变。
答
这在我以前也发生过。事实证明,Silverlight调试没有在Web项目的属性中启用。右键点击.Web项目并点击属性。接下来点击Web选项卡并在底部确保选中Silverlight复选框。
答
您必须具有该线路Application_Startup
:
WebContext.Current.Authentication.LoadUser(this.Application_UserLoaded, null);
使用Windows身份验证时,这将自动验证用户。
您是不是想要使用Active Directory中的组或者您打算自己管理组成员身份? – 2011-06-12 15:33:44
尝试禁用web.config文件中的匿名用户。但是当我需要知道用户名时,我调用了一个返回它的wcf服务方法。 – vorrtex 2011-06-12 19:05:04