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 6103585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:44:43+00:00 2026-05-23T13:44:43+00:00

I’m trying to use a custom role provider in an MVC3 app. I’ve already

  • 0

I’m trying to use a custom role provider in an MVC3 app. I’ve already got the membership provider working ok using Ninject but can’t seem to get the role provider working. The Membership provider doesn’t require a parameterless constructor but role provider does. Here’s some code snippets:

Web.config

<membership>
  <providers>
    <clear/>
    <add name="MyMembershipProvider" type="MyApp.Models.NHibernateMembershipProvider" 
         applicationName="myApp" />
  </providers>
</membership>

<roleManager enabled="true">
  <providers>
    <add name="MyRolesProvider" type="MyApp.Models.NHibernateRoleProvider"
         applicationName="myApp" />
  </providers>
</roleManager>

I have a Ninject module.

public class MyNinjectModule : NinjectModule
{
    public override void Load()
    {
        this.Bind<ISession>().ToMethod(
            x => MyApp.MvcApplication.SessionFactoryData.GetCurrentSession());

        // Respository
        this.Bind<IUserRepository>().To<UserRepository>();
        this.Bind<MembershipProvider>().To<NHibernateMembershipProvider>();
        this.Bind<RoleProvider>().To<NHibernateRoleProvider>();
    }
}

The custom Membership provider

public class NHibernateMembershipProvider : MembershipProvider
{
    private IUserRepository _repo;

    public NHibernateMembershipProvider(IUserRepository repository)
    {
        _repo = repository;
    }
    ...

The role provider

public class NHibernateRoleProvider : RoleProvider
{

    private IUserRepository _repo;

    public NHibernateRoleProvider(IUserRepository repository)
    {
        _repo = repository;
    }
    ...

I then configure my controller to require an authorize

    [Authorize(Roles="Admin")]
    public ActionResult Edit(int? id)
    {
       ...

I get this error when starting the app.

Parser Error Message: No parameterless constructor defined for this object.

Source Error: 


Line 49:     <roleManager enabled="true">
Line 50:       <providers>
Line 51:         <add name="MyRolesProvider" type="MyApp.Models.NHibernateRoleProvider"
Line 52:              applicationName="myApp" />
Line 53:       </providers>

I can access the users through the membership provider, so the repository is being injected ok, but the roles provider seems to be different. Why does the role provider require a constructor-less parameter? Is there a simple way to get the role provider to work with Ninject. Any help appreciated.

  • 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-23T13:44:44+00:00Added an answer on May 23, 2026 at 1:44 pm

    Since the role provider, in this case the NHibernateRoleProvider is instantiated by the ASP.NET framework the best solution is to use the service locator pattern. The service locator pattern is normally considered to be an anti-pattern but sometimes you have to be pragmatic and accepted the limitation on the framework that is being used (in this case the ASP.NET framework).

    Assuming you are using an implementation of the IDependencyResolver interface for Ninject. The following code should work.

    public class NHibernateMembershipProvider : MembershipProvider
    {
        private IUserRepository _repo;
    
        public NHibernateMembershipProvider()
        {
            _repo = DependencyResolver.Current.GetService<IUserRepository>();
        }
    
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
We're building an app, our first using Rails 3, and we're having to build
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am using Paperclip to handle profile photo uploads in my app. They upload
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.