ntep vodka
ntep vodka

Reputation: 735

ASP.Net MVC 3 Configuration

i want to ask about ASP.Net Configuration. i have a project that use ASP.Net MVC3. and i use membership in my project. in my database server, there's 2 database for my project.

  1. aspnetdb, contains aspnet_membership, aspnet_user, aspnet_roles, etc (i use asp.net Configuration)
  2. mydatabase, its for my project database.

now my boss told me that he want to host my project in public and told me to use only one database. so i have to move aspnetdb to mydatabase. how can i do it without making new table in mydatabase ?

thanks

Upvotes: 1

Views: 1252

Answers (2)

amiry jd
amiry jd

Reputation: 27585

By default the ASP.NET membership provider uses a built-in connectionString named LocalSqlServer which is something like this:

<add name="LocalSqlServer" 
     connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" 
     providerName="System.Data.SqlClient"/>

and when you use the Membership for first time (or when you use the web configuration manager tool), the aspnetdb.mdf will be created automatically. For first step, you can remove this connectionString from web.config by clear command:

  <connectionStrings>
    <clear/>
    <!-- your other connectionStrings -->
  </connectionStrings>

and also, you must change the connectionString for membershipProvider (and also roleProvider if you use it) in web.config file:

<membership userIsOnlineTimeWindow="20">
  <providers>
    <clear />
    <add
         connectionStringName="YourSpecifiedConnectionString" // your connectionString here
         name="AspNetSqlMembershipProvider" 
         type="System.Web.Security.SqlMembershipProvider" 
         enablePasswordRetrieval="false" 
         enablePasswordReset="true" 
         requiresQuestionAndAnswer="false" 
         requiresUniqueEmail="false" 
         maxInvalidPasswordAttempts="500" 
         minRequiredPasswordLength="1"
         minRequiredNonalphanumericCharacters="0"
         passwordAttemptWindow="10"
         applicationName="/" />
  </providers>
</membership>

<roleManager enabled="true">
  <providers>
    <clear/>
    <add connectionStringName="YourSpecifiedConnectionString" // your connectionString here
         name="AspNetSqlRoleProvider"  
         applicationName="/" 
         type="System.Web.Security.SqlRoleProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </providers>
</roleManager>

For configure the database to use ASP.NET built-in membership provider, you can use regsql tool which can be founded here:

C:\Windows\Microsoft.NET\Framework\(version that you are using. mine is v4.0.30319)\

In this folder, find the aspnet_regsql.exe file and run it. A helpful wizard will be shown and help you step by step to configure new database. And about your final issue: You haven't to apply any change to your edmx file! The EF works with tables you supplied to it, and membershipProvider do its job with tables that ASP.NET supplied to it! Well done, Good job!

Upvotes: 1

jgauffin
jgauffin

Reputation: 101130

You have to add those tables to your own database. It's quite easy. Just use the aspnet_regsql tool to export the database schema to a SQL file and run that file in your own database.

Instruction: http://www.xdevsoftware.com/blog/post/Install-ASPNET-Membership-Provider-on-a-Shared-Hosting-Company.aspx

Upvotes: 0

Related Questions