MOSS用那么久了,有人采用AD认证,有人采用FORM认证,我们公司是采用中间的替换方法,因为采用FORM认证个人觉得还是不是太方便,例如需要开两个端口等。个人有个做法把经验共享给大家,如果做得不对或者有更好的办法的话,可以联系我。
1.原因
为什么要进行表单登录,默认MOSS采用AD认证,是因为用户默认存储为AD,如果有人要把用户和以前的系统进行结合的方式,那么请采用正规的FORM认证进行开发。
我今天要讲的是AD认证,AD认证有个不好的方式就是弹出对话框,界面不友好,例如我要在界面上放一个忘记密码的方式是完全做不到的。
本帖包含图片[收藏图片]:

现在教大家一种采用表单进行提交的简单方法。其实这个办法很早的时候十一就搞过,不复杂,我只是稍微完善了一下。
1.首先采用匿名访问。
1.1IIS开启匿名访问。
本帖包含图片[收藏图片]:

1.2验证提供程序需要开启。操作方式:管理中心--》应用程序管理--》应用程序安全性--》验证提供程序--》默认
本帖包含图片[收藏图片]:

1.3开启网站匿名访问。操作为:网站操作--》高级权限--》设置--》匿名访问,如下
本帖包含图片[收藏图片]:

2.设置登录界面
我们需要开发一个登录界面。输入用户。密码。
本帖包含图片[收藏图片]:

这个登录界面可以放在_LAYOUTS/目录底下。
登录界面代码请见附件。
需要改几个地址如下:
../../sharepoint/test/default.aspx 这个界面是需要验证的界面(默认网站已经开了匿名,只需要验证到其他一个非匿名访问的地址即可)
http://10.49.28.7 这个是我们要返回的界面
如果还不清楚的。可以访问http://keji.lickies.cn 查看。
3.登录后自动跳转到登录界面的方式,因为我们已经开放了匿名,默认我们是可以进去的,那么我们需要增加一段程序,判断如果AD用户为空的话则跳转到登录界面。
我们采用一个办法是在MASTERPAGE里增加一个USERCONTROL
如何做呢?打开默认的在12/TEMPLATE/GLOBRAL/DEFAULT.MASTER(如果有改过则到SPD里找)
在
<%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Welcome.ascx" %>
下增加
<%@ Register TagPrefix="wssuc" TagName="login" Src="~/_controltemplates/chklogin9.ascx" %>
在<BODY scroll="yes" onload="javascript:if (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();">
下增加
<wssuc:login id="chklogin" runat="server" EnableViewState="false"></wssuc:login>
可能很多人在问CHKLOGIN.ascx是啥。
就是我们的用户控件,,,这个文件如下。附件可以下载。。
<%@ Control Language="C#" Inherits="Microsoft.SharePoint.ApplicationPages.WebControls.ActionBar,Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" compilationMode="Always" %>
<%@ Register Tagprefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%
if(HttpContext.Current.User.Identity.Name.ToString()=="")
{
Response.Redirect("/_layouts/web/login.aspx");
}
%>
请把这个文件放到c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES下即可。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>协同办公门户登陆</title>
<script language='JavaScript' type='text/javascript'>
var objXmlHttp = null;
function DoSend(URL)
{
//return false;
var struser=document.getElementById("username").value;
if (struser=="")
{
alert("请输入用户名!");
document.getElementById('username').focus();
return false;
}
var strpwd = document.getElementById("password").value;
if(strpwd=="")
{
alert("请输入密码!");
document.getElementById('password').focus();
return false;
}
document.getElementById("divVerify").style.visibility='visible';
//alert("dodo('"+URL+"','"+struser+"','"+strpwd+"')");
setTimeout("dodo('"+URL+"','"+struser+"','"+strpwd+"')",80);
}
function dodo(URL,struser,strpwd){
//alert('dd');
var objXmlHttp = new ActiveXObject('MICROSOFT.XMLHTTP');
try
{
objXmlHttp.open("GET","" + URL ,false,struser,strpwd);
objXmlHttp.send();
if(objXmlHttp.status =="200")
{
if(window.location.href.indexOf("http://192.168")>=0)
{
window.location.href = " http://192.168.8.103";
}
else
{
window.location.href = " http://keji.lickies.cn";
}
}
else
{
alert("请输入正确的帐号密码!");
document.getElementById("divVerify").style.visibility='hidden';
document.getElementById('password').focus();
return false;
}
}
catch(em)
{
alert(em.message);
}
}
</script>
</head>
<body>
<div>
<form method="post">
<table align="center" cellpadding="0" cellspacing="0" style="background-image: url('images/login/login_e.jpg');
width: 702px; height: 350px; margin-top:90px"><tr style="vertical-align:top"><td>
<table cellspacing="0" cellpadding="0" style="margin-top:130px; width: 302px; height: 121px; margin-left:360px; position:relative">
<tr>
<td style="width: 80px; height: 40px;">
<div align="center" style="font-family: 宋体; font-weight: bold; color: cornflowerblue; font-size: small;">
用户名:</div></td>
<td style="height: 40px; width: 160px;" align="center">
<input id="username" name="username" onkeypress="if(event.keyCode=='13'){document.getElementById('password').focus();}"
style="width: 94%" type="text" /><span
style="color: #ff3333"></span></td>
<td align="left" style="height: 40px">
<span style="color: #ff3333; font-size: small;">拼音</span></td>
</tr>
<tr>
<td style="height: 40px; width: 80px;">
<div align="center" style="font-family: 宋体; font-weight: bold; color: cornflowerblue; font-size: small;">
密 码:</div></td>
<td style="height: 40px; width: 160px;" align="center">
<input id="password" name="password" onkeypress="if(event.keyCode=='13'){document.getElementById('btnIn').click();}"
style="width: 94%" type="password" /></td>
<td align="center" style="height: 40px">
</td>
</tr>
<tr>
<td align="center" colspan="3" style="height: 27px">
<img src="images/login/login_a.gif" alt="" id="btnIn" onclick="return DoSend('/sharepoint/default.aspx');" />
<a id="hosturl" target="_self" href="/"><img border=0 src="images/login/login_b.gif" alt=""></a>
<script>
var rootUrl=window.location.host;
var backUrl="";
if(rootUrl=="192.168.2.7")
{
backUrl="192.168.2.2";
}
else
{
backUrl="10.49.28.2";
}
document.all.item("hosturl").href="http://"+backUrl+"/usermanage/forgetpassword.aspx";
</script>
</td>
</tr>
<tr>
<td colspan="3" align="center" style="height: 19px">
<div id="divVerify" style="visibility:hidden;color:red;">
正在验证中,请稍候...</div>
</td>
</tr>
</table>
</td></tr></table>
</form>
</div>
</body>
</html>
出错的话是帐号和密码不对你要修改<img src="images/login/login_a.gif" alt="" id="btnIn" onclick="return DoSend('/sharepoint/default.aspx');" />
把这个地址改为你的地址