Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4325378
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:15:31+00:00 2026-05-21T09:15:31+00:00

HI, I am implementing a custom role provider in my nhibernate application I have

  • 0

HI,

I am implementing a custom role provider in my nhibernate application
I have a repository that I call whenever I want to access the 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 override

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

//I then filter and so on

    }

But when this function is called I always get an error that the NHibernate session is closed.
I debugged the nhibernate source code and it turns out that the session here has a different guid that the session in my controllers(I am using ASP.NET MVC also).
And this particular session is closed by the time I get here.
I don’t know who closes it. I know it is started when the application starts and only then.

Does anyone have any idea what I am doing wrong?
I want to still use Nhibernate in this provider but not get the error any more.
Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:15:31+00:00Added an answer on May 21, 2026 at 9:15 am

    This is how I evetually fixed it.

    in my repository class I had this:

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

    I deleted the constructor entirely
    I put in this instead:

    private ISession _session;
            protected ISession Session
            {
                get
                {
                    if (_session == null)
                    {
                        _session = SessionManager.GetCurrentSession();
                    }
                    return _session;
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Implementing a custom membership provider, there are certain properties such as MinRequiredPasswordLength that only
I'm implementing a custom control that inherits from Control . I want it to
I need some help implementing a custom role provider in a asp.net mvc app.
I'm currently implementing a custom MultiPageEditorPart where I want to have multiple pages when
I am implementing a custom ASP.NET membership provider that operates based on the custom
I'm implementing a custom IPrincipal that I want to use across multiple applications. I
I have created my own Role Provider because I found the one that ASP.Net
When implementing a custom membership provider I see that the underlying data model has
I am implementing a custom membership provider by inheriting from MembershipProvider. I have my
As I was going through implementing a custom role provider I came across these

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.