Web Administration Tool database with IIS

531 views Asked by At

I have created a website for my university that requires membership. I used the web administration tool from Visual Studio and created Users and Rules.When i test it from Visual Studio it works fine. The Web Administration Tool automatically creates a SQL database named ASPNETDB.MDF in the App_Data folder that saves membership data. My question is will the database work when i add the website at the IIS? Do i have to create a sql server database and add a connection?Please answer me.It's really important. i only want a very basic membership.

1

There are 1 answers

0
jaedgahuva On

You can use db from /App_Data as explained in this SO answer:
ASP.NET: How to deploy App_Data to webhost? - but it depends on your server set up.

When using Membership my preference is to run it from a separate db in either SQL / SQL Express, as then have choice to run IIS site and db on different servers if required. Also better for security / scaling etc.

Once db is created you can use aspnet_regsql.exe to install Membership services into the db. It's usually located here - c:\Windows\Microsoft.NET\Framework\< versionNumber >\aspnet_regsql.exe. Can run as GUI or command line:
http://msdn.microsoft.com/en-us/library/x28wfk74.aspx

When running Membership from a separate db you'll also need to configure a provider in web.config. Something along the lines of this:

<connectionStrings>
    <remove name="LocalSqlServer" />
    <add name="MyMembershipConnectionString" 
    connectionString="Data Source=SERVER123\SQLEXPRESS;Initial Catalog=Database123;Persist Security Info=True;User ID=User123;Password=Password123" providerName="System.Data.SqlClient" />
</connectionStrings>

in < System.Web > section:

<roleManager defaultProvider="MySqlRoleProvider" enabled="true" 
    cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="30" 
    cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
  <providers>
    <clear />
    <add name="MySqlRoleProvider" type="System.Web.Security.SqlRoleProvider"
        connectionStringName="MyMembershipConnectionString" applicationName="MyAppName" />
  </providers>
</roleManager>

<membership defaultProvider="MySqlMembershipProvider" userIsOnlineTimeWindow="720">
  <providers>
    <clear />
    <add name="MySqlMembershipProvider" 
         type="System.Web.Security.SqlMembershipProvider" 
         connectionStringName="MyMembershipConnectionString" 
         enablePasswordRetrieval="false" 
         enablePasswordReset="true" 
         requiresQuestionAndAnswer="false" 
         requiresUniqueEmail="true" 
         passwordFormat="Hashed" 
         minRequiredPasswordLength="8" 
         minRequiredNonalphanumericCharacters="0" 
         passwordStrengthRegularExpression="((?=.*\d)(?=.*[a-z]).{6,20})" 
         maxInvalidPasswordAttempts="5" 
         passwordAttemptWindow="30" />
  </providers>
</membership>

I've used a similar set up to this a good few times with no problems. If using db from /App_Data you shouldn't need to do any of the web.config stuff