关于Moss 2007 Form认证的随笔,一定要使用FORM认证吗?

新的MOSS 2007可以给开发者留下的巨大的开发空间,其中之一就是网站再也可以不必使用AD认证。

先前网站上讨论的所谓的Form认证可以导致SharePoint Designer不能打开网站的情况,也可以简单地通过在IE里点“使用SharePoint Designer编辑”按钮,完美地解决。

但是大家就一定要使用FORM 认证嘛?

诚然,FORM认证给我们的提供了巨大的开发空间,但是同时也增加了代码的开发量,由于在做企业解决方案时,用户的数量是一定的,不可能每天有大量的注册用户,域用户认证可以完美地通过域认证来解决权限机制。但是如果这个网站也要兼顾对外对客户进行服务的功能,比如客户要定期登录网站进行申报,这时其实可以通过AD或服务器本身的“本地用户”来解决这个问题。

由于笔者所开发的环境,企业本身并没有进行AD的部署,那么如果要使用认证又不太想使用复杂的AD和FORM,其实完全可以通过使用WEB PART或是在工作流的Action中加入本地用户管理的代码来实现用户的增加删除,从来实现“注册”,“删除”,等功能。

进一步讨论,你甚至可以通过建立一个特殊的“自定义用户列表”并给这个列表邦定上“用户管理工作流”,当有列表有增加和删除时就启动相应的工作流,来扩展“本地用户”属性不足(你可以定义任何属性)的问题。

其实,另一个方案更也比较有引力,但不能使用邦定工作流,就是使用MOSS对象模型中的,UserProFile模型,但是不知道怎么回事,同样的代码,UserProfileManager UPM=new UserProfileManager(context);我在“控制台程序”里面就可以WalkThough, 但是当我在另一个列表的工作流的Action中使用就怎么也通不过。

下面是我收集的“本地用户管理”一些有用的示例:


取得登录名(比如PCNAME\UserName的全名为“管理员”)的全名(可以“我的电脑”右击“管理”看出)自定义SharePoint 工作流 Action:
   
 

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
using Microsoft.SharePoint.Security;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office .Server .UserProfiles ;


using System.DirectoryServices;

using System.Web;
namespace JsGasActivityLibrary1
{
    
public partial class Activity1: SequenceActivity
    
{
        
public static DependencyProperty UserTextProperty = System.Workflow.ComponentModel.DependencyProperty.Register("UserText"typeof(string), typeof(Activity1));
        [ValidationOption(ValidationOption.Optional)]
        [Description(
"This is the description which appears in the Property Browser")]
        [Category(
"This is the category which will be displayed in the Property Browser")]
        [Browsable(
true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        
public string UserText
        
{
            
get
            
{
                
return ((string)(base.GetValue(Activity1.UserTextProperty)));
            }

            
set
            
{
                
base.SetValue(Activity1.UserTextProperty, value);
            }

        }


        
public static DependencyProperty StrOutProperty = System.Workflow.ComponentModel.DependencyProperty.Register("StrOut"typeof(string), typeof(Activity1));
        [ValidationOption(ValidationOption.Optional)]
        [Description(
"This is the description which appears in the Property Browser")]
        [Category(
"This is the category which will be displayed in the Property Browser")]
        [Browsable(
true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        
public string StrOut
        
{
            
get
            
{
                
return ((string)(base.GetValue(Activity1.StrOutProperty)));
            }

            
set
            
{
                
base.SetValue(Activity1.StrOutProperty, value);
            }

        }


       
      

        
public Activity1()
        
{
            InitializeComponent();
        }


       

        
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
        
{


            DirectoryEntry AD 
= new DirectoryEntry("WinNT://" +
                                Environment.MachineName 
+ ",computer");
            DirectoryEntry NewUser 
= AD.Children.Find(UserText.Substring (UserText .IndexOf ("\\")+1) , "user");
            StrOut 
= NewUser.InvokeGet("FullName").ToString();



          
                     

            


        }

    }

}



下面是给本机增加一个用户名TestUser1,密码#12345Abc,全名:我的用户,描述:Test User from .Net的代码片。

 try
        
{
            DirectoryEntry AD 
= new DirectoryEntry("WinNT://" +
                                Environment.MachineName 
+ ",computer");
            DirectoryEntry NewUser 
= AD.Children.Add("TestUser1""user");
            NewUser.Invoke(
"SetPassword"new object[] "#12345Abc" });
            NewUser.Invoke(
"Put"new object[] "Description""Test User from .NET" });
            NewUser.Invoke(
"Put"new object[] "FullName""我的用户" });
            NewUser.CommitChanges();
            DirectoryEntry grp;

            grp 
= AD.Children.Find("Guests""group");
            
if (grp != null{ grp.Invoke("Add"new object[] { NewUser.Path.ToString() }); }
            Console.WriteLine(
"Account Created Successfully\r\n" + NewUser.InvokeGet ("FullName").ToString ());
            Console.ReadLine();
        }

        
catch (Exception ex)
        
{
            Console.WriteLine(ex.Message);
            Console.ReadLine();

        }





 

posted @ 2007-03-22 00:07  dosboy  阅读(2682)  评论(6编辑  收藏  举报