using custom IPrincipal and IIdentity in MVC3

前端 未结 1 1859
借酒劲吻你
借酒劲吻你 2020-12-08 02:41

I create my own IPrincipal and IIdentity implementation as shown below:

[ComVisible(true)]
[Serializable]
public sealed class Custo         


        
1条回答
  •  太阳男子
    2020-12-08 03:21

    Your mistake is here:

    _application.AuthenticateRequest += ApplicationAuthenticateRequest;
    

    There is a HttpModule named RoleManagerModule that invokes a method in HttpApplication.PostAuthenticateRequest and sets the HttpContext.Current.User to RolePrincipal. So, you were setting the User in AuthenticateRequest and the RoleManagerModule sets it in PostAuthenticateRequest, means after your set, so overrides your settings. Change your Module.Init:

    public void Init(HttpApplication context) {
        _application = context;
        // change just this line:
        _application.PostAuthenticateRequest += ApplicationAuthenticateRequest;
    }
    

    IMPORTANT UPDATE:

    Please see this question -asked by starter again, depended on current question- for a second solution, if this one doesn't work.

    0 讨论(0)
提交回复
热议问题