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 ...
随机推荐
- DEDE使用AJAX无刷新提交Form表单,PHP返回结果
$query = "INSERT INTO `{$diy->table}` (`id`, `ifcheck` $addvar) VALUES (NULL, 0 $addvalue); ...
- linux下查看进城(ps)的方法 与 杀死进程(kill)的N种方法
PS查看进程 inux上进程有5种状态: 1. 运行(正在运行或在运行队列中等待) 2. 中断(休眠中, 受阻, 在等待某个条件的形成或接受到信号) 3. 不可中断(收到信号不唤醒和不可运行, 进程必 ...
- html 跳转页面,同时跳转到一个指定的位置
比如我现在 a.html 的时候,我想跳转到 b.html ,并且是 b.html 的某一个位置,用 <a href=>, a.html里: <a href="b.html ...
- 64位CentOS5.6安装Mysql 5.5.11GA
1.更新并查看当前CentOS版本是否为5.6yum updatelsb_release -a 2.下载文件下载 bison-2.4.3.tar.gz到/usr/local/src下载 cmake-2 ...
- uvalive4015 (树上背包)
给一棵树,边上有权值,然后给一个权值x,问从根结点出发, 走不超过x的距离,最多能经过多少个结点. 走过的点可以重复走,所以可以从一个分支走下去,然后走回来,然后再走另一个分支 dp[u][j][0] ...
- mysql替换字段里数据内容部分字符串(亦可用于增加字段中的内容)
mysql替换表的字段里面内容,如例子: mysql> select host,user from user where user='testuser'; +----------------- ...
- HTTPDNS成为移动互联网的标配–原因与原理解析(转)
DNS,作用就是将域名解析成IP.一个DNS查询,先从本地缓存查找,如果没有或者已经过期,就从DNS服务器查询,如果客户端没有主动设置DNS服务器,一般是从服务商DNS服务器上查找.这就出现了不可控. ...
- EJB通过ANT提高EJB应用程序的开发效率、无状态发展本地接口bean、开发状态bean
该jboss集成到eclipse 关掉Jboss控制台新闻Ctrl+c,在MyEclipse→Servers→Jboss可配置JBoss. 通过ANT提高EJB应用的开发效率 在HelloWorld ...
- android升级软件版本号,您安装后的新版本号,成功安装画面没有出现,或直接回到桌面
Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //an ...
- 清除Android工程中没用到的资源(转)
项目需求一改再改,UI一调再调,结果就是项目中一堆已经用不到但却没有清理的垃圾资源,不说工程大小问题,对新进入项目的人或看其他模块的代码的人来说,这些没清理的资源可能也可能会带来困扰,所以最好还是清理 ...