[英]How to Create A New SQL User For Aspnetdb Membership Db?
I have created a membership database using the asp_regsql.exe
tool instead of the default wizard on an existing database. 我使用
asp_regsql.exe
工具而不是现有数据库的默认向导创建了成员数据库。 When I create new user account with membership createuser
method for aspnetdb
membership database, I get below error: 当我为
aspnetdb
成员资格数据库创建具有成员资格createuser
方法的新用户帐户时,出现以下错误:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. 建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible.
服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
(提供者:SQL网络接口,错误:26-指定服务器/实例时出错)
I am using VS 2013. 我正在使用VS 2013。
my aspnetdb
database name is : SecurityTutorials.mdf
我的
aspnetdb
数据库名称是: SecurityTutorials.mdf
my web.config setting : 我的web.config设置:
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="newsdbConnectionString"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\newsdb.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="SecurityTutorialsConnectionString"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\SecurityTutorials.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<httpRuntime targetFramework="4.5" />
</system.web>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
my CreatingUserAccounts.aspx.cs code is : 我的CreatingUserAccounts.aspx.cs代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.UI.HtmlControls;
public partial class Membership_CreatingUserAccounts : System.Web.UI.Page
{
const string passwordQuestion = "What is your favorite color";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) SecurityQuestion.Text = passwordQuestion;
}
protected void CreateAccountButton_Click(object sender, EventArgs e)
{
MembershipCreateStatus createStatus;
MembershipUser newUser = System.Web.Security.Membership.CreateUser(Username.Text,
Password.Text,
Email.Text,
SecurityQuestion.Text,
SecurityAnswer.Text,
true, out createStatus);
switch (createStatus)
{
case MembershipCreateStatus.Success:
CreateAccountResults.Text = "The user account was successfully created!";
break;
case MembershipCreateStatus.DuplicateUserName:
CreateAccountResults.Text = "There already exists a user with this username.";
break;
case MembershipCreateStatus.DuplicateEmail:
CreateAccountResults.Text = "There already exists a user with this email address.";
break;
case MembershipCreateStatus.InvalidEmail:
CreateAccountResults.Text = "There email address you provided in invalid.";
break;
case MembershipCreateStatus.InvalidAnswer:
CreateAccountResults.Text = "There security answer was invalid.";
break;
case MembershipCreateStatus.InvalidPassword:
CreateAccountResults.Text = "The password you provided is invalid. It must be seven characters long and have at least one non-alphanumeric character.";
break;
default:
CreateAccountResults.Text = "There was an unknown error; the user account was NOT created.";
break;
}
}
}
you should add below lines to <system.web></system.web>
block,and of course customize the code as you need 您应该在
<system.web></system.web>
块中添加以下<system.web></system.web>
行,并且当然可以根据需要自定义代码
<authentication mode="Forms">
<forms name="/.ASPXAUTH" loginUrl="~/ui/public/ads.aspx" defaultUrl="~/ui/Public/ads.aspx" protection="All" timeout="525600" path="/" requireSSL="false" slidingExpiration="true" cookieless="UseDeviceProfile"/>
</authentication>
<roleManager enabled="true"/>
<membership defaultProvider="AspNetSqlMembershipProvider" userIsOnlineTimeWindow="30" hashAlgorithmType="">
<providers>
<clear/>
<add connectionStringName="LocalSqlServer" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="True" passwordFormat="Encrypted" maxInvalidPasswordAttempts="15" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</membership>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.