ASP.Net MVC 3 Configuration

大憨熊 提交于 2019-12-11 10:39:11

问题


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


回答1:


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!




回答2:


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



来源:https://stackoverflow.com/questions/7526018/asp-net-mvc-3-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!