SharePoint 2010 Form Authentication (SQL) based on existing database
SharePoint 2010 表单认证,基于现有数据库的用户信息表
本文主要描写叙述本人配置过程中涉及到的步骤,仅作为參考,不要仅限于此步骤。
另外本文通俗易懂,适合大众口味儿。
I. 开启并配置基于声明的身份验证
打开SharePoint 2010 Management Shell,依次运行下面语句
$app = Get-SPWebApplication "<your webapp url>"
$app.UseClaimsAuthentication = "true"
$app.Update()
进入管理中心->应用程序管理->管理Web应用程序,选中上面的webapp,点击身份验证提供程序,点击默认链接弹出验证配置窗体。
勾选“启用基于窗口的身份验证(FBA)”,填入名称,这里用mp和rp举例,之后会用到;登录页URL这里,能够默认也能够自己定义,这里我选择了自己定义,是自己写的一个登录页。

点击保存完毕第一步骤。
II. WebConfig配置
须要配置mp和rp的位置有三个,各自是管理中心、webappport相应的IIS文件夹,以及{SharePoint Root}\WebServices\SecurityToken文件夹下的web.config文件
须要加入的内容例如以下
<membership defaultProvider="i">
<providers>
<!--将下面节点加入到指定位置-->
<add name="mp" type="<assembly>" />
</providers>
</membership>
<roleManager defaultProvider="c" enabled="true" cacheRolesInCookie="false">
<providers>
<!--将下面节点加入到指定位置-->
<add name="rp" type="<assembly>" />
</providers>
</roleManager>
<connectionStrings>
<add connectionString="<connStr>" name="Conn" />
</connectionStrings>
当中assembly为自己定义Provider的dll的描写叙述,后面会提到;connStr为数据库连接串。
III. 自己定义MembershipProvider
大致的思路是写两个sealed类,mp继承MembershipProvider,rp继承RoleProvider,我的环境中没实用到角色,所以rp仅仅做了继承,凝视掉了
rp代码
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.Security; namespace Providers
{
public sealed class rp : RoleProvider
{
private bool mWriteExceptionsToEventLog = false; public bool WriteExceptionsToEventLog
{
get
{
return mWriteExceptionsToEventLog;
}
set
{
mWriteExceptionsToEventLog = value;
}
} public override void Initialize(string name, NameValueCollection config)
{
base.Initialize(name, config);
} private string pApplicationName = ""; public override string ApplicationName
{
get
{
return pApplicationName;
}
set
{
pApplicationName = value;
}
} public override void AddUsersToRoles(string[] usernames, string[] rolenames)
{
throw new NotImplementedException();
} public override void CreateRole(string rolename)
{
throw new NotImplementedException();
} public override bool DeleteRole(string rolename, bool throwOnPopulatedRole)
{
throw new NotImplementedException();
} public override string[] GetAllRoles()
{
return null;
} public override string[] GetRolesForUser(string username)
{
return null;
} public override string[] GetUsersInRole(string rolename)
{
return null;
} public override bool IsUserInRole(string username, string rolename)
{
return false;
} public override void RemoveUsersFromRoles(string[] usernames, string[] rolenames)
{
throw new NotImplementedException();
} public override bool RoleExists(string rolename)
{
return false;
} public override string[] FindUsersInRole(string rolename, string usernameToMatch)
{
return null;
} private static List<string> GetAllUsers()
{
return null;
} private static List<string> FindAllRoles()
{
return null;
} private List<string> FindRolesForUser(string username)
{
return null;
}
}
}
mp最少实现下面四个方法,完毕在SharePoint上查找加入用户以及登录逻辑的自己定义处理。
GetAllUsers、GetUser、ValidateUser、FindUsersByName
我这里大致的做法就是用Webconfig中加入的数据库连接串去操作现有数据库的用户表,尝试用Entities可是好像行不通
写好后将dll加入强命名,部署到GAC。
IV. 番外-自己定义登录页
自己定义登录页,没什么难度,直接贴代码了
ASPX
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %> <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="Authentication.login" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script language="javascript" for="document" event="onkeydown">
if (event.keyCode == 13) {
document.getElementById("<%=btnLogin.ClientID %>").click();
}
</script>
<script language="javascript" type="text/javascript">
function login() {
if (document.getElementById("<%=txtUserName.ClientID %>").value == "") {
alert('请输入username');
return;
}
if (document.getElementById("<%=txtPassword.ClientID %>").value == "") {
alert('请输入password');
return;
}
document.getElementById("<%=btnLogin.ClientID %>").click();
}
</script>
</head>
<body>
<form action="" id="form" runat="server">
<table border="0" cellspacing="0" cellpadding="0" class="login_table">
<tr>
<td class="login_td" align="center">
<div class="logan_contai">
<div class="login_box" style="height: 488px;">
<div class="login_top">
<div class="login_top_wel">
欢迎使用</div>
<div class="login_top_nav">
</div>
</div>
<div class="login_main png">
<asp:Literal ID="ltError" runat="server"></asp:Literal>
<div class="login_txt_box">
<ul>
<li>
<div class="login_name">
username</div>
<div class="login_inpbox">
<asp:TextBox ID="txtUserName" runat="server" CssClass="login_input" onfocus="this.className='login_input_hov'"
MaxLength="100" onblur="this.className='login_input'"></asp:TextBox>
<div class="login_wrong">
</div>
</div>
</li>
<li>
<div class="login_name">
密 码</div>
<div class="login_inpbox">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" CssClass="login_input"
onfocus="this.className='login_input_hov'" MaxLength="100" onblur="this.className='login_input'"></asp:TextBox>
</div>
<div class="login_wrong">
</div>
</li>
<li>
<div class="login_btn" style="width: 191px; padding: 9px 0 0 155px;">
<a href="#" title="" onclick="login()">登 录</a></div>
<div style="display: none;">
<asp:Button CssClass="login_btn" Width="191px" ID="btnLogin" runat="server" Text="登录"
OnClick="btnLogin_Click" Style="padding: 9px 0 0 155px" />
</div>
</li>
</ul>
</div>
</div>
<div class="login_foot png">
</div>
</div>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
CS
using System;
using System.Web.UI;
using Microsoft.SharePoint.IdentityModel; namespace Authentication
{
public partial class login : Page
{
protected void Page_Load(object sender, EventArgs e) { } protected void btnLogin_Click(object sender, EventArgs e)
{
Login(this.txtUserName.Text, this.txtPassword.Text);
} private void Login(string username, string passwrod)
{
try
{
bool status = SPClaimsUtility.AuthenticateFormsUser(Request.Url, username, passwrod);
if (!status)
{
ltError.Text = "用户名或password错误,请又一次输入!";
}
else
{
if (Request.QueryString["ReturnUrl"] != null && Request.QueryString["ReturnUrl"] != "")
{
Response.Redirect(Request.QueryString["ReturnUrl"]);
}
else if (Request.QueryString["Source"] != null && Request.QueryString["Source"] != "")
{
Response.Redirect(Request.QueryString["Source"]);
}
else
{
Response.Redirect("~/");
}
}
}
catch (Exception ex)
{
ltError.Text = "系统错误:<br />";
ltError.Text = ex.Message;
}
}
}
}
以上就是大致的步骤。PS:在搜索加入SharePoint用户的时候,无法显示成名称,仅仅能显示登录名,还不知道怎样解决。
SharePoint 2010 Form Authentication (SQL) based on existing database的更多相关文章
- 『SharePoint 2010』Sharepoint 2010 Form 身份认证的实现(基于AD)
一.进管理中心,创建一个应用程序,配置如下: 二.填端口号,和选择form身份认证,以及填写成员和角色,其他都默认就可以了 三.使用SharePoint 2010 Management Shell在里 ...
- 『SharePoint 2010』Sharepoint 2010 Form 身份认证的实现(基于SQL)
1:创建一个基于身份认证的应用程序(具体参见上篇基于AD) SQL-MembershipProvider 成员SQL-RoleManager 角色 2:修改管理中心,我们创建的应用程序,还有Web服务 ...
- How to tune SharePoint 2010 Server for better performance?
http://social.technet.microsoft.com/wiki/contents/articles/7926.sharepoint-2010-tips-for-dealing-wit ...
- 【SharePoint 2010】SharePoint 2010开发方面的课堂中整理有关问题
SharePoint 2010开发方面的课堂中整理有关问题陈希章 ares@xizhang.com1. 对于SharePoint的体系结构不甚清楚,觉得有点乱了解了就不会觉得乱了,请理解1) 场服务 ...
- SharePoint 2010开发方面的课堂中整理有关问题
SharePoint 2010开发方面的课堂中整理有关问题 这是我这几天在做一个SharePoint开发的课程的时候,大家提出的一些问题,及我的解答,分享给更多的朋友参考一下 这个文档,也可以在这里下 ...
- Developing a Custom Membership Provider from the scratch, and using it in the FBA (Form Based Authentication) in SharePoint 2010
//http://blog.sharedove.com/adisjugo/index.php/2011/01/05/writing-a-custom-membership-provider-and-u ...
- 解决Sharepoint 2010 custom display form 不显示附件的问题
sharepoint 2010用designer添加自定义的 display form默认是不会显示附件的. 需要添加如下代码才会显示附件: <tr> <td width=" ...
- 清理SharePoint 2010的SQL Server 2008 R2日志数据库的方法!
//来源:http://www.cnblogs.com/nbpowerboy/p/3380079.html 公司用SharePoint 2010已有三年多的时间了,上BPM项目也有2年多的时间,之前供 ...
- Searching External Data in SharePoint 2010 Using Business Connectivity Services
from:http://blogs.msdn.com/b/ericwhite/archive/2010/04/28/searching-external-data-in-sharepoint-2010 ...
随机推荐
- html+css实现登录界面
<!DOCTYPE html> <style type="text/css"> body{ background-color: #555555; } #ti ...
- mysql主键设置成auto_increment时,进行并发性能測试出现主键反复Duplicate entry 'xxx' for key 'PRIMARY'
mysql主键设置成auto_increment时,进行并发性能測试出现主键反复Duplicate entry 'xxx' for key 'PRIMARY' 解决方法: 在my.cnf的[mysql ...
- APUE学习--网络编程(3)
本篇文章介绍TCP通信. 上文提到传输层的两个协议TCP和UDP,UDP是无连接的已经介绍过,TCP是面向连接的,阐述建立连接和断开连接前先来看下TCP报文头的结构. 报文头在linux的定义在/us ...
- Linux中块设备驱动程序分析
基于<Linux设备驱动程序>书中的sbull程序以对Linux块设备驱动总结分析. 開始之前先来了解这个块设备中的核心数据结构: struct sbull_dev { i ...
- LAMBDA表达式常用 (全)
这里主要是将数据库中的常用操作用LAMBDA表达式重新表示了下,用法不多,但相对较常用,等有时间了还会扩展,并将查询语句及LINQ到时也一并重新整理下: 1.select语句:books.Select ...
- live555 for Android
因为Live555 包中未提供Android 的config 所以编译器来比較麻烦,须要自己编写Android.mk ,下面是我通过 改动 现有的config文件,在cygwin实现 编译的过程,co ...
- Windows7在自由的虚拟机(微软官方虚拟机)
Windows7在自由的虚拟机(微软官方虚拟机) 前言: 不是说windows7自带的虚拟机最好用,但他的正式版.免费.只是希望你能windows7用户.它将能够自由使用: 还是Vmware. 微软为 ...
- 执行Sql块
import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import oracle.C ...
- 初步C++类模板学习笔记
类模板 实现:在上课时间的定义给它的一个或多个参数,这些参数代表了不同的数据类型. -->抽象的类. 在调用类模板时, 指定參数, 由编 ...
- js如果你想删除您问
if (confirm("OK删除?") == true)