Sparkle
Sparkle

Reputation: 2469

MVC 3 sub Site?

I have a very basic site that works fine on its own but when I create a duplicate of the site and attempt to add it to a sub domain (then convert it to a application) I get a error when I attempt to any controller which has the below settings at the top:

public class AccountController : Controller
{

    // This constructor is used by the MVC framework to instantiate the controller using
    // the default forms authentication and membership providers.
    private CustomMembershipDB datacontext;
    public AccountController()
        : this(null, null)
    {
        datacontext = new CustomMembershipDB();
    }
    // This constructor is not used by the MVC framework but is instead provided for ease
    // of unit testing this type. See the comments at the end of this file for more
    // information.
    public AccountController(IFormsAuthentication formsAuth, IMembershipService service)
    {
        FormsAuth = formsAuth ?? new FormsAuthenticationService();
        MembershipService = service ?? new AccountMembershipService();
    }

    public IFormsAuthentication FormsAuth
    {
        get;
        private set;
    }

    public IMembershipService MembershipService
    {
        get;
        private set;
    } 

Error I get:

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: The entry 'EFMembershipProvider' has already been added.

IIS seems to be complaining about a duplicate Membership provider being set on the same domain and not sure simply renaming it will solve this one? Any Idea appreciated as I'm a newbie and this is above me!

Upvotes: 0

Views: 781

Answers (1)

Stéphane Bebrone
Stéphane Bebrone

Reputation: 2763

I suppose that your "subsite" is a virtual directory of the first one. Root's Web.config settings are inherited to virtual directories.

That means that by default your subsite gets all providers declared in your top site.

To prevent this behavior you can use this directive inheritInChildApplications=false on your main Web.config or simply avoid to (re)declare the EFMembershipProvider in your subsite.

Upvotes: 1

Related Questions