开发者

Asp.net Membership Provider custom CreateUser

开发者 https://www.devze.com 2023-03-27 06:36 出处:网络
I am trying to get my custom \"CREATEUSER\" to work but I think I\'m having problems in my web.config.Thanks to help here, I\'ve gotten the MEMBERSHIP section written but my MEMBERSHIP.CREATEUSER comm

I am trying to get my custom "CREATEUSER" to work but I think I'm having problems in my web.config. Thanks to help here, I've gotten the MEMBERSHIP section written but my MEMBERSHIP.CREATEUSER command is failing to logon to the database. The error is, "Cannot logon to the default database." I've added a connection string and the name is in my section. But I'm stuck.

Here is the code-behind file for creating the user:

        protected void submit_Click(object sender, EventArgs e)
        {

                Membership.CreateUser(userName.Text, passwdConfirm.Text, email.Text);

        }

And, here is my Web.config file.

<configuration>

  <connectionStrings>
      <add name="FVTCEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.ms开发者_开发知识库l;provider=System.Data.SqlClient;provider connection string=&quot;data source=SFP;attachdbfilename=H:\ASP.Net\FVRG\FVRG\App_Data\FVTC.mdf;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      <add name="dbMembership" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=H:\ASP.Net\FVRG\FVRG\App_Data\ASPNETDB.MDF;User Instance=true" providerName="System.Data.SqlClient" />
  </connectionStrings>
    <system.web>
        <authorization>
            <allow roles="ADMIN" />
            <allow roles="GUEST" />
        </authorization>
        <roleManager enabled="true" />
        <authentication mode="Forms" />
        <compilation debug="true" targetFramework="4.0" />

      <membership>

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

      </membership>
    </system.web>

  <appSettings>
    <add key="DatabaseConnection" value="Data Source=.\SQLEXPRESS;AttachDbFilename=H:\ASP.Net\FVRG\FVRG\App_Data\FVTC.mdf;Integrated Security=True;User Instance=True" />
  </appSettings>
</configuration>

thanks in advance for your help!


That error typically arises because of the account being used to access the database. Each account setup in the database is given a default database, and the default database setup for this user either does not exist, or the user does not have access to it. This has to be done on the database server.

HTH.

0

精彩评论

暂无评论...
验证码 换一张
取 消