一次登录,资源尽享(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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值