MOSS & SSO 系列1

最近写了几个SSO的WebParts,发现了些问题,于是提出共参:
Step1: 引用相关的DLL
   using Microsoft.SharePoint.Portal.SingleSignon;
   using Microsoft.SharePoint.Portal;
或者你可以直接这么做:编辑当前项目的Web.config的<assemblies></assemblies>
加入:
    <add assembly="Microsoft.SharePoint.Portal.SingleSignon, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/>
    <add assembly="Microsoft.SharePoint.Portal.SingleSignon.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/>
    <add assembly="Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71E9BCE111E9429C"/>

Step2: 配置MOSS上的SSO
    (简单,暂且不表)注意多半要在数据库登录帐户中添加:NT AUTHORITY\ANONYMOUS LOGON 给个可以创建数据库和管理权限的即可!

Step3:Coding...
     2种写法都可以,暂不明白? 
    写法1                    string strSSOLogonFormUrl = SingleSignonLocator.GetCredentialEntryUrl("DEMOSSO");
                    string[] rgGetCredentialData = null;
                    Credentials.GetCredentials(1, "DEMOSSO", ref rgGetCredentialData);
                    string strName = rgGetCredentialData[0];
                    string strPwd = rgGetCredentialData[1];
                    ......
写法2         IntPtr pUserName = IntPtr.Zero;
         IntPtr pPassword = IntPtr.Zero;
         ISsoProvider isso = SsoProviderFactory.GetSsoProvider();
         SsoCredentials myCreds = isso.GetCredentials("DEMOSSO");

          pUserName = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(myCreds.UserName);
          pPassword = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(myCreds.Password);
          string uName = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(pUserName);
          string uPwd = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(pPassword);

END: 
   catch (SingleSignonException ssoe)
                {
                    if (SSOReturnCodes.SSO_E_CREDS_NOT_FOUND == ssoe.LastErrorCode)
                    {
                        Context.Response.Redirect(strSSOLogonFormUrl);
                    }
                    else
                    {
                        Response.Redirect(strSSOLogonFormUrl);
                    }
                }

 Step4:读Exchange Server 2007 的新邮件
 
引用WebServices先:ICredentials creds = new NetworkCredential(userNaem, rgGetCredentialData[1], "demo");
                    // ICredentials creds = CredentialCache.DefaultNetworkCredentials;//("mailadmin", "Pass!word", "demo")

                    exchangeServer.Credentials = creds;
                    exchangeServer.Url = @"https://mlc.demo.cn/ews/exchange.asmx";

                    DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
                    folderIDArray[0] = new DistinguishedFolderIdType();
                    folderIDArray[0].Id = DistinguishedFolderIdNameType.inbox;

                    PathToUnindexedFieldType ptuftDisplayName = new PathToUnindexedFieldType();
                    ptuftDisplayName.FieldURI = UnindexedFieldURIType.folderDisplayName;

                    PathToExtendedFieldType pteftComment = new PathToExtendedFieldType();
                    pteftComment.PropertyTag = "0x3004"; // PR_COMMENT
                    pteftComment.PropertyType = MapiPropertyTypeType.String;

                    GetFolderType myfoldertype = new GetFolderType();
                    myfoldertype.FolderIds = folderIDArray;
                    myfoldertype.FolderShape = new FolderResponseShapeType();
                    myfoldertype.FolderShape.BaseShape = DefaultShapeNamesType.IdOnly;
                    myfoldertype.FolderShape.AdditionalProperties = new BasePathToElementType[2];
                    myfoldertype.FolderShape.AdditionalProperties[0] = ptuftDisplayName;
                    myfoldertype.FolderShape.AdditionalProperties[1] = pteftComment;

                    GetFolderResponseType myFolder = exchangeServer.GetFolder(myfoldertype);

                    FolderInfoResponseMessageType firmtInbox =
                        (FolderInfoResponseMessageType)myFolder.ResponseMessages.Items[0];
                    PathToUnindexedFieldType ptuftSubject = new PathToUnindexedFieldType();
                    ptuftSubject.FieldURI = UnindexedFieldURIType.itemSubject;

                    PathToUnindexedFieldType ptuftBody = new PathToUnindexedFieldType();
                    ptuftBody.FieldURI = UnindexedFieldURIType.itemAttachments;

                    PathToExtendedFieldType pteftFlagStatus = new PathToExtendedFieldType();
                    pteftFlagStatus.PropertyTag = "0x1090"; // PR_FLAG_STATUS
                    pteftFlagStatus.PropertyType = MapiPropertyTypeType.Integer;

                    FindItemType findItemRequest = new FindItemType();
                    findItemRequest.Traversal = ItemQueryTraversalType.Shallow;
                    findItemRequest.ItemShape = new ItemResponseShapeType();
                    findItemRequest.ItemShape.BaseShape = DefaultShapeNamesType.Default;

                    findItemRequest.ParentFolderIds = new FolderIdType[1];
                    findItemRequest.ParentFolderIds[0] = firmtInbox.Folders[0].FolderId;

                    FindItemResponseType firt = exchangeServer.FindItem(findItemRequest);

                    MessageType mt = new MessageType();
                    int newEmail = 0;//Unread email number
                    int totalEmail = 0;//Total Email number
                    foreach (FindItemResponseMessageType firmtMessage in firt.ResponseMessages.Items)
                    {
                        if (firmtMessage.RootFolder.TotalItemsInView > 0)
                        {
                            totalEmail = firmtMessage.RootFolder.TotalItemsInView;
                            foreach (ItemType it in ((ArrayOfRealItemsType)firmtMessage.RootFolder.Item).Items)
                            {
                                mt = it as MessageType;
                                if (mt != null)
                                {
                                    //this.TextBox1.Text += string.Format(string.Format("是否已读: {0} <br>", mt.IsRead.ToString()));
                                    if (!mt.IsRead)
                                        newEmail++;
                                    else
                                        continue;
                                }

                                #region Eg codes
                                //Response.Write(string.Format("<br><br>标题: {0} <br>", it.Subject));
                                //Response.Write(string.Format("<br><br>标题: {0} <br>", it.Subject)+string.Format("发件人: {0} <br>", mt.IsRead.ToString()));
                                //Response.Write(string.Format("收件人: {0} <br>", it.DisplayTo));
                                //Response.Write(string.Format("抄送人: {0} <br>", it.DisplayCc));
                                //Response.Write(string.Format("大小: {0} <br>", it.Size.ToString()));
                                //Response.Write(string.Format("<br><br>标题: {0} <br>", it.Subject)+string.Format("发件人: {0} <br>", mt.IsRead.ToString())+string.Format("重要性: {0} <br>", it.Importance.ToString()));
                                Response.Write(string.Format("是否已读: {0} <br>", ((MessageType)(it)).IsRead.ToString()));
                                Response.Write(string.Format("是否已读: {0} <br>", it.is));
                                //Response.Write(string.Format("附件: {0} <br>", it.HasAttachments.ToString()));
                                //Response.Write(string.Format("接收时间: {0} <br>", it.DateTimeReceived.ToString()));
                                //if (it.Body != null)
                                //{
                                //    Response.Write(string.Format("正文: {0} <br>", it.Body.Value));
                                //}

                                //if (null != it.ExtendedProperty)
                                //{
                                //    Response.Write(string.Format("Prop 0x1090: {0}\n\n", it.ExtendedProperty[0].Item.ToString()));
                                //}
                                //else
                                //{
                                //    Response.Write(string.Format("Prop 0x1090: not found"));
                                //}
                                #endregion
                            }
                        }
                    }
                    Response.Write(newEmail.ToString() + "//" + totalEmail.ToString());


Step5:AJAX更新结果

 
基本的例子,总邮件数顺便也可以拿到的。。。
    
    下回谈谈如何与OWA集成起来!

转载于:https://www.cnblogs.com/pccai/archive/2008/07/03/1235013.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值