c# - RoleManagerModule 和 RolePrincipal 对象

标签 c# asp.net authentication forms-authentication roles

根据我的书,如果启用角色管理,则 RoleManagerModule 通过将 RolePrincipal 对象分配给 HttpRequest.User< 创建用户的安全上下文。但是 FormsAuthenticationModule 是否已经创建安全上下文(因此主体对象被分配给 HttpContext.User ),它在 RoleManagerModule 之前被调用叫什么?

我问这个,因为在下面的代码中分配给 HttpRequest.User 的主体对象已经存在,即使 RoleManagerModule 还没有被调用:

protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
    if (User.Identity.IsAuthenticated && Roles.Enabled)
    {
        //here we subscribe user to a role via Roles.AddUserToRole()
    }       
}

主体对象也是如此,由 FormsAuthenticationModule 创建并分配给 HttpRequest.User,后来被 RolePrincipal 对象替换(由 创建RoleManagerModule)?

最佳答案

根据 this article :

If the Roles framework is enabled, the RoleManagerModule HTTP Module steps in after the FormsAuthenticationModule and identifies the authenticated user’s roles during the PostAuthenticateRequest event, which fires after the AuthenticateRequest event. If the request is from an authenticated user, the RoleManagerModule overwrites the GenericPrincipal object created by the FormsAuthenticationModule and replaces it with a RolePrincipal object. The RolePrincipal class uses the Roles API to determine what roles the user belongs to.

所以你是对的。

关于c# - RoleManagerModule 和 RolePrincipal 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/870839/

相关文章:

c# - LINQ to Entities 无法识别 Replace 方法?

php - 在php中维护一个登录用户到一个帐户

c# - 我可以在 linq 中实现属性并且不调用方法两次吗?

c# - FileSystemWatcher 不触发事件

c# - 是否已添加事件处理程序?

asp.net - 如何确定 JavaScript 中 RadioButtonList 的 SelectedValue?

c# - IIS 混合匿名和 Windows 身份验证

angularjs - locationChangeStart 和防止路线改变

c# - Windows 8 需要创建向导自定义控件

c# - 从 ASP.NET 应用程序中删除 ASP.NET_SessionId