1、问题及分析:
虽然我们利用shaerpoint2013的Welcome页面中的ID_LoginAsDifferentUser方法可以实现切换用户的功能,但是我们使用域登录是假单点模式,会导致用户切换用户后,再次访问依然是上一次登录的用户,而不是当前用户,原因就是域的账户密码会保存到windows凭证中,知道原因我们就可以分析怎么处理。
2、处理:
利用cmd中的命令清除windows凭证cmdkey /delete:IP,将该功能在我们的后台去执行就可以了,不管是C#\Jave网上是有后台执行cmd命令的方法,Java的自行搜索,目前我只是贴出C#代码:
[WebMethod]
public static string DeleteCmdKey(string IP)
{
string strInput = "cmdkey /delete:" + IP;
Process p = new Process();
//设置要启动的应用程序
p.StartInfo.FileName = "cmd.exe";
//是否使用操作系统shell启动
p.StartInfo.UseShellExecute = false;
// 接受来自调用程序的输入信息
p.StartInfo.RedirectStandardInput = true;
//输出信息
p.StartInfo.RedirectStandardOutput = true;
// 输出错误
p.StartInfo.RedirectStandardError = true;
//不显示程序窗口
p.StartInfo.CreateNoWindow = true;
//启动程序
p.Start();
//向cmd窗口发送输入信息
p.StandardInput.WriteLine(strInput + "&exit");
p.StandardInput.AutoFlush = true;
//获取输出信息
string strOuput = p.StandardOutput.ReadToEnd();
//等待程序执行完退出进程
p.WaitForExit();
p.Close();
return strOuput;
}
3、注销页面处理
shaerpoint注销页(signout)是网站集生成时自动创建的,点击注销跳转的页面可知地址,自行查询本系统的文件夹地址,增加js方法:
<SharePoint:ScriptBlock runat=“server”>
$.ajax({
url: “/_layouts/15/Handler/Threshold.aspx/DeleteCmdKey”,
type: “post”,
data: “{IP:‘xxxxxxxx’}”,
contentType: “application/json;charset=utf-8”,
dataType: ‘json’,
cache: true,
success: function (text) {
var TotalCount = text.d;
},
error: function (jqXHR, errorThrown) {
}
});
function _spBodyOnLoad() {
window.close();
}
</SharePoint:ScriptBlock>
备注:经过多轮测试,该方法在网站中调用后,只能删除掉服务器端的windows凭证,删除不了客户端的windows凭证,新方法后续新文章。