简体   繁体   中英

.NET Membership in ASP.NET MVC4 and Entity Framework with Oracle as Db

I will be starting an ASP.NET MVC 4 project soon with Entity Framework as my ORM and Oracle as my database engine.

I know that in order to get EF to work with Oracle, the tables have to be manually created in Oracle and the entities mapped to the table column by column.

The problem is my application has Authentication and Authorization needs and I was wondering what the easiest way would be to get the .NET membership to work with my scenario.

I have found this article , but it makes use of third party software that I find expensive.

I am using Oracle Developer Tools for .NET (ODT), and it has been a great help. The best part: it's free! ODT includes ODP.NET and will help you do the following:

  • automatically set up ASP.NET membership tables. You'll need to create the schema first, then run the scripts provided.
  • automatically create and map EF entities (using database first); you will not need to manually map tables to tables.

Some things to consider... My membership schema is separate from the schemas used for my application. This way I can use one membership schema for several applications that may rely on different databases (schemas/users).

When configuring web.config, be sure to change the application name from "/" to something meaningful. Several config elements reference the application name, so be sure to change for all. The membership provider will automatically create the application record in the membersip database schema.

After your membership schema has been created (with the scripts), you'll need to change the web.config file's membership, profile, and roleManager elements to something like this:

<membership defaultProvider="OracleMembershipProvider">
  <providers>
    <clear />
    <add name="OracleMembershipProvider" type="Oracle.Web.Security.OracleMembershipProvider, Oracle.Web, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342" connectionStringName="OraAspNetConnectionString" applicationName="YOUR_APP_NAME" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" />
  </providers>
</membership>
<profile>
  <providers>
    <clear />
    <add name="OracleProfileProvider" type="Oracle.Web.Profile.OracleProfileProvider, Oracle.Web, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342" connectionStringName="OraAspNetConnectionString" applicationName="YOUR_APP_NAME" />
  </providers>
</profile>
<roleManager enabled="true" defaultProvider="OracleRoleProvider">
  <providers>
    <clear />
    <add connectionStringName="OraAspNetConnectionString" applicationName="YOUR_APP_NAME" name="OracleRoleProvider" type="Oracle.Web.Security.OracleRoleProvider, Oracle.Web, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
  </providers>
</roleManager>

This link may also help

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM