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 ...
随机推荐
- Android使用应用程序资源(、颜色数组、尺寸、弦、布尔、整型)
一.Android资源分类详细解释 1.Android资源类别 Android中的资源分为两大类 : 可直接訪问的资源, 无法直接訪问的原生资源; -- 直接訪问资源 : 这些资源能够使用 R. ...
- poj Budget
Budget 建图好题.不知道为什么提交一直TLE. 然后.该了几次,看了别人的普通网络流都过了. 我觉得可能是卡DINIC的某些部分吧.这题就是一道普通的上下界最小流. 建图麻烦,所以说一下建图吧. ...
- AIX 中以并发模式挂载vg
要想以并发模式挂载VG 必须要有/usr/sbin/gsclvmd 这个进程,而些进程是安装HACMP 的必要的文件集bos.clvm.enh,同时gsclvmd 也是由HACMP 启动的,多个节点挂 ...
- 从零開始学android<ImageSwitcher图片切换组件.二十六.>
ImageSwitcher组件的主要功能是完毕图片的切换显示,比如用户在进行图片浏览的时候.能够通过button点击一张张的切换显示的图片,并且使用ImageSwitcher组件在每次切换的时候也能够 ...
- 深入浅出KnockoutJS
深入浅出KnockoutJS 写在前面,本文资料大多来源网上,属于自己的学习笔记整理. 其中主要内容来自learn.knockoutjs.com,源码解析部分资料来自司徒正美博文<knockou ...
- Codeforces Round #198 (Div. 2) C. Tourist Problem (数学+dp)
C. Tourist Problem time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Windows Phone开发(4):框架和页
原文:Windows Phone开发(4):框架和页 在开如之前,我想更正一个小问题,之前我在第一篇文章中说,Visual Studio Express for Windows Phone的中文版没有 ...
- OpenMp高速分拣
#include <stdio.h> #include<stdafx.h> #include<iostream> #include <stdlib.h> ...
- MySQL基金会-基本数据库操作
1. 删除数据库 DROP DATABASE 数据库名; mysql> drop database test; 即删除数据库模式 2 .创建数据库 create DATABASE 数据库名; m ...
- crontab,想说爱你不easy
悲剧的背景 跑自己主动化脚本的机器连不上toastserver了, 仅仅能自己写个脚本每天跑了. 当然要放在crontab里了. 5 3 * * * sh ~/nosecron.sh 更悲剧的结果 第 ...