更新时间:2023-12-02 16:14:40
是的,您需要在web.config中修改连接字符串.
Yes, you'll need to modify your connection strings in the web.config.
在web.config中,您可能会在<membership>
元素中看到类似的内容:
Look in the web.config, you'll probably see something like this in the <membership>
element:
<membership>
<providers>
<clear />
<add connectionStringName="LocalSqlServer"
name="AspNetSqlMembershipProvider"
[...]
type="System.Web.Security.SqlMembershipProvider,
System.Web,
Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>
connectionStringName
属性告诉框架在<connectionStrings>
元素中查找名为"LocalSqlServer"的连接字符串-您的web.config中可能未定义此字符串,因为它可以从Machine.Config中的继承. .Net Frameworks核心配置目录.
The connectionStringName
Attribute tells the framework to look in your <connectionStrings>
element for a connection string called "LocalSqlServer" - this may not be defined in your web.config as it can be inherited from the Machine.Config in the .Net Frameworks core config directory.
您可能应该为连接字符串选择一个新名称,并更新您的成员资格,角色和配置文件(如果您全部使用它们)提供程序以使用新名称.
You should probably pick a new name for the connection string, and update your membership, roles and profile (if you're using them all) providers to use the new name.
<connectionStrings>
元素中的内容如下:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="MyConnectionString"
connectionString="Data Source=[ServerName];Initial Catalog=[DatabaseName];Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
调整值以适合您的系统-我建议使用Integrated Security,而不是将数据库登录名和密码存储在web.config中,但是建议使用YMMV(例如,在共享主机上,我不能使用Integrated Security.必须提供用户/通行证详细信息.
Adjust the values to suit your systems - I'd recommend Integrated Security over storing your database login and password in the web.config, but YMMV (for example, on my shared host, I can't use Integrated Security, so have to supply user/pass details).
网站管理工具也将遵循这些连接字符串.
The Web Site admin tool will honour these connection strings as well.
编辑以回复评论
您是否已成功登录?还是创建了一个用户?我只想排除您已经配置了连接字符串并且可以正常工作?
Have you successfully logged in at all? Or created a user? I just want to rule out that you've the connection string configured and working?
您是否还配置并打开了角色提供程序?您是否在其中更新了"connectionStringName"属性?
Do you have the Roles Provider configured and turned on as well? Have you updated the "connectionStringName" attribute in there?
请注意,与以前一样,machine.config为您指定了一个默认角色提供程序,它试图指向本地SqlExpress实例-这可能是连接错误的来源.
Note that as before, the machine.config specifies a default role provider for you that attempts to point to a local SqlExpress instance - which is probably where the connection error is coming from.
<!-- Note enabled="true" - you need to turn this one on! -->
<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="MyConnectionString"
[...]
type="System.Web.Security.SqlRoleProvider,
System.Web,
Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>
有关消除属性的更多详细信息,我建议使用文档:
For more details on the elided attributes, I'd recommend the documentation:
roleManager Element
配置完成后,一切都会正常工作.
Once you've configured that, it should all work.
如果您无法创建用户/登录名,请检查:
If you've not been able to create a user/log in, I'd check:
data source
与您的服务器实例匹配(不总是仅是计算机名称,它可能类似于"MachineName \ SqlServer").aspnet_XXXX_FullAccess
角色中(角色,个性化,个人资料和角色各一个).data source
matches your server instance (not always just the name of your machine, it might be something like "MachineName\SqlServer").aspnet_
, to ensure that you can create users (which you'll need if you have a registration form) you should add the account to the aspnet_XXXX_FullAccess
roles (one each for Membership, Personalization, Profile and Roles).