废话不说了,我们来看看怎么实现的吧:
1:创建一个基于身份认证的应用程序(具体参见上篇基于AD)
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
SQL-MembershipProvider 成员
SQL-RoleManager 角色
SQL-RoleManager 角色
2:修改管理中心,我们创建的应用程序,还有Web服务里面的SecurityTokenServiceApplication 这个3个地方的web.config
每个地方都要加连接数据库的字符串(最好自己新建的账户访问数据库,不然可能访问不到数据)
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
<
connectionStrings
>
< add name ="SQLConnectionString" connectionString ="Data Source=jiangly;Initial Catalog=SQL-Auth;User ID=jly;password=P@ssw0rd" />
</ connectionStrings >
< add name ="SQLConnectionString" connectionString ="Data Source=jiangly;Initial Catalog=SQL-Auth;User ID=jly;password=P@ssw0rd" />
</ connectionStrings >
找到管理中心的<system.web></system.web>,配置如下:
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
<
roleManager
defaultProvider
="AspNetWindowsTokenRoleProvider"
enabled
="true"
cacheRolesInCookie
="false"
>
< providers >
< add connectionStringName ="SQLConnectionString" applicationName ="/" description ="Stores and retrieves roles from SQL Server" name ="SQL-RoleManager" type ="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</ providers >
</ roleManager >
< membership defaultProvider ="SQL-MembershipProvider" >
< providers >
< add connectionStringName ="SQLConnectionString" passwordAttemptWindow ="5" enablePasswordRetrieval ="false" enablePasswordReset ="false" requiresQuestionAndAnswer ="true" applicationName ="/" requiresUniqueEmail ="true" passwordFormat ="Hashed" description ="Stores and Retrieves membership data from SQL Server" name ="SQL-MembershipProvider" type ="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</ providers >
</ membership >
< providers >
< add connectionStringName ="SQLConnectionString" applicationName ="/" description ="Stores and retrieves roles from SQL Server" name ="SQL-RoleManager" type ="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</ providers >
</ roleManager >
< membership defaultProvider ="SQL-MembershipProvider" >
< providers >
< add connectionStringName ="SQLConnectionString" passwordAttemptWindow ="5" enablePasswordRetrieval ="false" enablePasswordReset ="false" requiresQuestionAndAnswer ="true" applicationName ="/" requiresUniqueEmail ="true" passwordFormat ="Hashed" description ="Stores and Retrieves membership data from SQL Server" name ="SQL-MembershipProvider" type ="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</ providers >
</ membership >
找到应用程序的<system.web></system.web>,配置如下
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
<!--</p><p>Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/</p><p>-->
<
membership
defaultProvider
="i"
>
< providers >
< add name ="i" type ="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
< add connectionStringName ="SQLConnectionString" passwordAttemptWindow ="5" enablePasswordRetrieval ="false" enablePasswordReset ="false" requiresQuestionAndAnswer ="true" applicationName ="/" requiresUniqueEmail ="true" passwordFormat ="Hashed" description ="Stores and Retrieves membership data from SQL Server" name ="SQL-MembershipProvider" type ="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</ providers >
</ membership >
< roleManager defaultProvider ="c" enabled ="true" cacheRolesInCookie ="false" >
< providers >
< add name ="c" type ="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
< add connectionStringName ="SQLConnectionString" applicationName ="/" description ="Stores and retrieves roles from SQL Server" name ="SQL-RoleManager" type ="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</ providers >
</ roleManager >
< providers >
< add name ="i" type ="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
< add connectionStringName ="SQLConnectionString" passwordAttemptWindow ="5" enablePasswordRetrieval ="false" enablePasswordReset ="false" requiresQuestionAndAnswer ="true" applicationName ="/" requiresUniqueEmail ="true" passwordFormat ="Hashed" description ="Stores and Retrieves membership data from SQL Server" name ="SQL-MembershipProvider" type ="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</ providers >
</ membership >
< roleManager defaultProvider ="c" enabled ="true" cacheRolesInCookie ="false" >
< providers >
< add name ="c" type ="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
< add connectionStringName ="SQLConnectionString" applicationName ="/" description ="Stores and retrieves roles from SQL Server" name ="SQL-RoleManager" type ="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</ providers >
</ roleManager >
找到SecurityTokenServiceApplication站台web.config,它里面没有<system.web></system.web>,你需要自己添加
3 改好后,自己创建一个用户(这个太简单了,我就不讲了哈),加入站点集里,完了。用这个账号去测试吧,哈哈
参考资料:
http://devmeat.com/show/5739564
![](https://i-blog.csdnimg.cn/blog_migrate/cdec0645add3fc3c328197dda5c76203.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/81178cc93a2a3bb5048d90d76e7ec935.gif)
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->
<
system.web
>
< roleManager defaultProvider ="c" enabled ="true" cacheRolesInCookie ="false" >
< providers >
< add name ="c" type ="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
< add connectionStringName ="SQLConnectionString" applicationName ="/" description ="Stores and retrieves roles from SQL Server" name ="SQL-RoleManager" type ="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</ providers >
</ roleManager >
< membership defaultProvider ="i" >
< providers >
< add name ="i" type ="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
< add connectionStringName ="SQLConnectionString" passwordAttemptWindow ="5" enablePasswordRetrieval ="false" enablePasswordReset ="false" requiresQuestionAndAnswer ="true" applicationName ="/" requiresUniqueEmail ="true" passwordFormat ="Hashed" description ="Stores and Retrieves membership data from SQL Server" name ="SQL-MembershipProvider" type ="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</ providers >
</ membership >
< roleManager defaultProvider ="c" enabled ="true" cacheRolesInCookie ="false" >
< providers >
< add name ="c" type ="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthRoleProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
< add connectionStringName ="SQLConnectionString" applicationName ="/" description ="Stores and retrieves roles from SQL Server" name ="SQL-RoleManager" type ="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</ providers >
</ roleManager >
< membership defaultProvider ="i" >
< providers >
< add name ="i" type ="Microsoft.SharePoint.Administration.Claims.SPClaimsAuthMembershipProvider, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
< add connectionStringName ="SQLConnectionString" passwordAttemptWindow ="5" enablePasswordRetrieval ="false" enablePasswordReset ="false" requiresQuestionAndAnswer ="true" applicationName ="/" requiresUniqueEmail ="true" passwordFormat ="Hashed" description ="Stores and Retrieves membership data from SQL Server" name ="SQL-MembershipProvider" type ="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</ providers >
</ membership >