Search code examples
asp.net.netweb-configwindows-hosting

web.config and membership database - from development to production


I'm trying to host my first ASP.NET project, after the initial upload via FTP I got SQL connection Errors, so after doing some searching I figured it was my Connection String, so I fixed it by properly putting my hosts info:

 <add name="orangefreshConnectionString1" connectionString="Data Source=<server>;Initial Catalog=<catalog>;User Id=<user>;Password=<pwd>;" providerName="System.Data.SqlClient" />

So this fixed my problem, my Website is up now... except for when I try to login, I get another SQL connection error.

I use 2 databases on my website: dbstart and ASPNETDB (last one for membership)

ASPNETDB is handled on my development web.config as: providers>

      <clear />
      <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
  </providers>

I know there is something that needs to be changed here, but my google queries have not been helpful so far in finding an answer...

Here is my development web.config content:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <add name="orangefreshConnectionString1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\orangefresh.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
    <add name="orangefreshEntities" connectionString="metadata=res://*/App_Code.Orangefresh.csdl|res://*/App_Code.Orangefresh.ssdl|res://*/App_Code.Orangefresh.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\orangefresh.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <system.web>
    <customErrors mode="Off"/>
      <membership>
          <providers>
              <clear />
              <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
          </providers>
      </membership>
    <roleManager enabled="true" />
      <authentication mode="Forms">
          <forms loginUrl="default.aspx"></forms>
      </authentication>
    <pages theme="orangefresh" />
    <compilation debug="false" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
      </assemblies>
      <buildProviders>
        <add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" />
      </buildProviders>
    </compilation>
    <httpRuntime requestValidationMode="2.0" />
  </system.web>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="João &lt;email@email.com&gt;">
        <network host="host" userName="user" password="pass" />
      </smtp>
    </mailSettings>
  </system.net>
    <location path="Management">
        <system.web>
            <authorization>
                <allow roles="Admin"/>
                <deny users="*"/>
            </authorization>
        </system.web>
    </location>
</configuration>

How can I properly refer to my membership database on web.config?


Solution

  • Change inside of this:

    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
    

    the

    connectionStringName="LocalSqlServer"
    

    to

    connectionStringName="orangefreshConnectionString1" 
    

    or

    connectionStringName="orangefreshEntities"
    

    I can't tell which connection you use for what, but that is what needs changed.