SqlRoleProvider 无法连接到数据库
我使用标准 SqlRoleProvider 对角色进行了以下配置,但是当我尝试在网站管理工具中打开安全页面时出现错误:
<roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">
<providers>
<remove name="AspNetSqlRoleProvider"/>
<add name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="PoyntingInstallationConnectionString"
applicationName="/" />
</providers>
</roleManager>
数据库具有所有角色表等。
I have the following config for roles using standard SqlRoleProvider, but I get an error when I try and open the Security page in the wweb site Admin tool:
<roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">
<providers>
<remove name="AspNetSqlRoleProvider"/>
<add name="AspNetSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="PoyntingInstallationConnectionString"
applicationName="/" />
</providers>
</roleManager>
The DB has all the role tables etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保
PoyntingInstallationConnectionString
位于您的 web.config 中,配置正确,并且指向包含您的表的数据库。这些角色将是 aspnet_Roles 表中的条目,而不是数据库角色。并且没有默认角色,因此首次运行脚本时该表应该为空。
编辑:您能否提供有关如何创建身份验证数据库的更多详细信息?即,您是直接运行 aspnet_regsql 工具,还是单独生成并运行脚本?
编辑 2:aspnet_regsql 工具很容易运行 - 它位于 .NET Framework v2.0 文件夹中。 (默认位置 C:\Windows\Microsoft.NET\Framework\v2.0.50727)
有很多参数可用于从命令行运行,或者如果您不带参数运行它,它将打开一个向导,该向导将逐步执行你通过它。请注意,使用该向导,您可以获得对所有会员提供商功能(个人资料、个性化、网络事件...)的支持,即使您不打算使用它们。
我建议您运行它,然后将结果与现有数据库进行比较。是否有人运行该工具,然后将表复制到另一个数据库,而没有意识到还需要一堆其他东西?我只是尝试从命令行和向导运行该工具,它生成了所有角色、过程等。
正确运行时,您应该有一堆表(至少 6 个)、存储过程(几十个或所以 - 我的有 35 个)和数据库角色(至少 6 个),名称以
aspnet_
开头,以及一堆视图(至少 5 个),名称以vw_aspnet_
开头。如果您缺少其中的任何部分,该提供程序将无法工作。我通常从命令行运行它,这样我只能获取成员身份和角色信息。这会大大减少噪音,但这也是为什么我上面的数字有点模糊的原因。 :)
Ensure that
PoyntingInstallationConnectionString
is in your web.config, is configured correctly, and points at the database that contains your tables.The roles would be entries in the aspnet_Roles table, not database roles. And there are no default roles, so the table should be empty when you first run the script.
Edit: Can you provide more details on how you created the auth DB? I.e. did you run the aspnet_regsql tool directly, or did you generate and run the scripts separately?
Edit 2: The aspnet_regsql tool is easy enough to run - it is in the .NET Framework v2.0 folder. (Default location C:\Windows\Microsoft.NET\Framework\v2.0.50727)
There are a bunch of parameters that can be used to be run from the command line, or if you run it without parameters it will open a wizard that steps you through it. Note that, using the wizard, you get support for all of the membership provider features (profiles, personalization, web events...) even if you don't intend to use them.
I'd suggest that you run it and then compare the results with your existing database. Did someone run the tool and then just copy the tables over to another database without realizing that there was a bunch of other stuff required as well? I just tried running the tool both from the command line and wizard, and it generated all of the roles, procs, etc.
When run correctly, you should have a bunch of tables (at least 6), stored procedures (a couple dozen or so - mine has 35) and DB roles (at least 6) with names starting with
aspnet_
, and a bunch of views (at least 5) with names starting withvw_aspnet_
. If you're missing any part of these, the provider won't work.I typically run it from the command line so that I only get the membership and role stuff. That will cut down on the noise quite a bit, but is also why my numbers above are a little fuzzy. :)