Asp.net nhibernate user role error

Hi

I use my own role provider in my nhibernate application. I have a repository that I call whenever I want to access an nhibernate session.

So, when my role provider initializes itself

public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) {

            base.Initialize(name, config);
            Repository = new Repository();
        }

Then i redefine

public override string[] GetRolesForUser(string username) {
        var users = Repository.QueryAll<Users>();

// Then I filter, etc.

    }

But when this function is called, I always get an error that the NHibernate session is closed. I debugged the source code of nhibernate, and it turns out that in this session there is another guide that has a session in my controllers (I also use ASP.NET MVC). And this particular session is closed by the time I come here. I do not know who closes it. I know that it starts when the application starts and only then.

- , ? - Nhibernate , .

+3
2

.

:

public Repository()
{
    this.Session = SessionManager.GetCurrentSession();
}

:

private ISession _session;
        protected ISession Session
        {
            get
            {
                if (_session == null)
                {
                    _session = SessionManager.GetCurrentSession();
                }
                return _session;
            }
        }
+1

. , . -, ISession , ISession, , .

, ISessionFactory GetCurrentSession, , ISession.

+2

Source: https://habr.com/ru/post/1783722/


All Articles