一次登录,资源尽享(Single Sign-On)


一次登录,资源尽享(Single Sign-On)
微软专家专题讲座



Single Sing-On简介

怎样配置Single Sign-On

启用 Single Sign-On

指定 Single Sign-on 和应用程序定义的设置

创建加密密钥

编辑应用程序定义

管理应用程序定义的帐户信息

创建使用SSO技术的Web Part

http://msdn.microsoft.com/library/en-us/dnspts/html/sharepoint_webparttemplates.asp
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Portal;
using Microsoft.SharePoint.Portal.SingleSignon;
//添加引用
using System.Net;
using System.IO;
//重新命名NameSpace为WPHttpRequest
namespace WPHttpRequest
{
[DefaultProperty("Text"),
ToolboxData("<{0}:HttpRequestWebPart runat=server></{0}:HttpRequestWebPart>"),
XmlRoot(Namespace="WPHttpRequest")]
//重新命名Class为WPHttpRequest
public class HttpRequestWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
//定义私有变量
private const string c_Url = "http://"; //目标URL
private const string defaultText = "";
private string text=defaultText;
private string _myurl = "";
[Category("Custom Properties")]
[DefaultValue(c_Url)]
[WebPartStorage(Storage.Personal)]
[FriendlyNameAttribute("Url")]
[Description("Type the Url here.")]
[Browsable(true)]
[XmlElement(ElementName="Url")]
//定义属性
public string Url //目标URL
{
get
{
return _myurl;
}
set
{
_myurl = value;
}
}
[Browsable(true),Category("Miscellaneous"),
DefaultValue(defaultText),
WebPartStorage(Storage.Personal),
FriendlyName("Text"),Description("Text Property")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
//重载RenderWebPart,并调用GetHttpRequestContent获取目标URL的内容
protected override void RenderWebPart(HtmlTextWriter output)
{
this.Text = GetHttpRequestContent(this.Url);
output.Write(Text);
}
//获取远端页面的信息
private string GetHttpRequestContent(string url)
{
string respstr = "";
try
{
Uri contentUrl = new Uri(url);
WebRequest req = WebRequest.Create(contentUrl);
//设置预先验证用户权限
req.PreAuthenticate = true;
//建立网络身份验证
string[] rgGetCredentialData = null;
Credentials.GetCredentials( 1,"SSOApp", ref rgGetCredentialData);
System.Net.NetworkCredential mycredential =
new System.Net.NetworkCredential(rgGetCredentialData[0],rgGetCredentialData[1],rgGetCredentialData[2]);
req.Credentials = mycredential;
//获取远端返回的文件流
WebResponse resp = req.GetResponse();
Stream stream = resp.GetResponseStream();
StreamReader sr = new StreamReader(stream);
//以字符串形式读取数据流
respstr = sr.ReadToEnd();
sr.Close();
}
catch (Exception ex)
{
//返回错误信息
return "Error: " + ex.Message;
}
return respstr;
}
}
}

<?xml version="1.0" encoding="utf-8"?>

<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" >

<Title>HttpRequestWebPart</Title>

<Description>HttpRequestWebPart.</Description>

<Assembly>WPHttpRequest</Assembly>

<TypeName>WPHttpRequest.HttpRequestWebPart</TypeName>

<!-- Specify default values for any additional base class or custom properties here. -->

</WebPart>

<?xml version="1.0"?>

<!-- You need to have just one manifest per CAB project for Web Part Deployment.-->

<!-- This manifest file can have multiple assembly nodes.-->

<WebPartManifest xmlns="http://schemas.microsoft.com/WebPart/v2/Manifest">

<Assemblies>

   <Assembly FileName="WPHttpRequest.dll">

     <SafeControls>

       <SafeControl

         Namespace="WPHttpRequest"

         TypeName="*"

       />

     </SafeControls>

   </Assembly>

</Assemblies>

<DwpFiles>

   <DwpFile FileName="WPHttpRequest.dwp"/>

</DwpFiles>

</WebPartManifest>

添加Web Part

相关文档

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/spptsdk/html/nsPortalSingleSignOn.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnspts/html/sharepoint_northwindwebparts.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/spptsdk/html/smpscCodeAccessSecurityDevs.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnspts/html/sharepoint_northwindwebparts.asp
posted @ 2006-07-28 11:03  XiaoK  阅读(230)  评论(0编辑  收藏  举报