Membership provider with different ApplicationName

2019-05-28 19:23发布

问题:

I have a web.config in my MVC3 application, I have an Admin area in my MVC3 application too.

On the front end I hook asp.net users into a Customers table and my application relies on this table to operate. In the Admin area I have an Administrator Role and User but this login also works for the front end. I can create a customer for my Admin so my application doesn't fail but ideally I would like to separate the logins from the front and Admin area.

I want to put a second web.config inside my Admin area that has a different application name so that the Admin account can never be logged into the front end. e.g.

    <profile>
      <providers>
        <clear />
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="SecurityConn" applicationName="/" />
      </providers>
    </profile>

But I don't know where to put this or if it is even possible

applicationName="/AdminArea"

回答1:

You can add more than one provider in the section with different applicationname.

What you will need to consider is how you would switch between those providers. You can use the providers collection e.g.

Membership.Providers["MyOtherProvider"].ValidateUser(username, pwd);

So you will need a mechanism to know who is logging in (Admin or customer).