首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

觅高人 关于用C# 编程 与EXCHANGE 最新遇到的問題

2011-12-20 
找高人 关于用C# 编程与EXCHANGE 最新遇到的問題我用的是这个API函数publicvirtualnewvoidNtAccountCreate

找高人 关于用C# 编程 与EXCHANGE 最新遇到的問題
我用的是这个   API   函数   public   virtual   new   void   NtAccountCreate   (   System.String   bstrDomain   ,   System.String   bstrUserLogin   ,   System.String   bstrPassword   ,   System.String   bstrUserComment   ,   System.String   bstrLocalGroup   )


using   System;
using   System.Collections;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Web;
using   System.Web.SessionState;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.HtmlControls;
using   MSExchangeAcctLib;
namespace   exchangetest
{
///   <summary>
///   Summary   description   for   WebForm1.
///   </summary>
public   class   WebForm1   :   System.Web.UI.Page
{
protected   System.Web.UI.WebControls.Button   Button1;
public   MSExchangeAcctLib.IAcctMgmt   sd;
             

private   void   Button1_Click(object   sender,   System.EventArgs   e)
{
//sd.NtAccountDelete( "utpcb.com ", "py-wang ");

/*/   public   abstract   new   void   NtAccountCreate   (   System.String   bstrDomain   ,   System.String   bstrUserLogin   ,   System.String   bstrPassword   ,   System.String   bstrUserComment   ,   System.String   bstrLocalGroup   )
        Member   of   MSExchangeAcctLib.IAcctMgmt
這些是介紹用法的   */


  sd.NtAccountCreate( "域名 ", "新加的用户 ", "新加的用户密码 ", " ", "所属的组 ");
TextBox1.Text= "nihao ";

}
 
        private   void   Page_Load(object   sender,   System.EventArgs   e)
{
//   Put   user   code   to   initialize   the   page   here
}

#region   Web   Form   Designer   generated   code
override   protected   void   OnInit(EventArgs   e)
{
//
//   CODEGEN:   This   call   is   required   by   the   ASP.NET   Web   Form   Designer.

InitializeComponent();
base.OnInit(e);
}

///   <summary>
///   Required   method   for   Designer   support   -   do   not   modify
///   the   contents   of   this   method   with   the   code   editor.
///   </summary>
private   void   InitializeComponent()
{        
this.Button1.Click   +=   new   System.EventHandler(this.Button1_Click);
this.Load   +=   new   System.EventHandler(this.Page_Load);

}
#endregion


}
}
我的目的很简单   就是按下BUTTON就能加入我写入的用户名和密码
环境是   WIN2000     2003.NET  
我运行点BUTTON后出现以下错误


Server   Error   in   '/exchangetest '   Application.
--------------------------------------------

存取被拒。  
Description:   An   unhandled   exception   occurred   during   the   execution   of   the   current   web   request.   Please   review   the   stack   trace   for   more   information   about   the   error   and   where   it   originated   in   the   code.  



Exception   Details:   System.UnauthorizedAccessException:   存取被拒。  

ASP.NET   is   not   authorized   to   access   the   requested   resource.   Consider   granting   access   rights   to   the   resource   to   the   ASP.NET   request   identity.   ASP.NET   has   a   base   process   identity   (typically   {MACHINE}\ASPNET   on   IIS   5   or   Network   Service   on   IIS   6)   that   is   used   if   the   application   is   not   impersonating.   If   the   application   is   impersonating   via   <identity   impersonate= "true "/> ,   the   identity   will   be   the   anonymous   user   (typically   IUSR_MACHINENAME)   or   the   authenticated   request   user.  

To   grant   ASP.NET   write   access   to   a   file,   right-click   the   file   in   Explorer,   choose   "Properties "   and   select   the   Security   tab.   Click   "Add "   to   add   the   appropriate   user   or   group.   Highlight   the   ASP.NET   account,   and   check   the   boxes   for   the   desired   access.

Source   Error:  


Line   34:  
Line   35:  
Line   36:   sd.NtAccountCreateNtAccountCreate( "域名 ", "新加的用户 ", "新加的用户密码 ", " ", "所属的组 ");
Line   37:  
Line   38:  
 

Source   File:   c:\inetpub\wwwroot\exchangetest\webform1.aspx.cs         Line:   36  

Stack   Trace:  


[UnauthorizedAccessException:   存取被拒。]
      MSExchangeAcctLib.AcctMgmtClass.NtAccountCreate(String   bstrDomain,   String   bstrUserLogin,   String   bstrPassword,   String   bstrUserComment,   String   bstrLocalGroup)   +0
      exchangetest.WebForm1.Button1_Click(Object   sender,   EventArgs   e)   in   c:\inetpub\wwwroot\exchangetest\webform1.aspx.cs:36
      System.Web.UI.WebControls.Button.OnClick(EventArgs   e)
      System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String   eventArgument)
      System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler   sourceControl,   String   eventArgument)
      System.Web.UI.Page.RaisePostBackEvent(NameValueCollection   postData)
      System.Web.UI.Page.ProcessRequestMain()

 


--------------------------------------------
Version   Information:   Microsoft   .NET   Framework   Version:1.1.4322.2032;  

ASP.NET   Version:1.1.4322.2032  


請問這個錯誤怎麽解決??   要設置什麽東西嗎?
還有這個是怎麽用的
sd.GetSidFromName(strDomain,strUsername,out   obSID);

[解决办法]
//Using acctcrt.dll
MSExchangeAcctLib.AcctMgmt objAcct = new MSExchangeAcctLib.AcctMgmtClass();

object obSID;
object obSD;
string strDCT = "2A864886F7140501 ";

objAcct.GetSidFromName(strDomain,strUsername,out obSID);


objMailbox.Properties[ "Assoc-NT-Account "].Add(obVal);
objAcct.GenerateSecDescriptor(strDomain,strUsername, out obSD);
objMailbox.Properties[ "NT-Security-Descriptor "].Add(obSD);
objMailbox.Properties[ "Deliv-Ext-Cont-Types "].Add(strDCT);
objMailbox.CommitChanges();
objMailbox.Close();

[解决办法]
你看看文件是否只读的;还有就是这样函数有没有用错
[解决办法]
http://www.cnblogs.com/umlchina/archive/2006/06/02/144768.html
[解决办法]
machine.config文件
processModel ... user=administrator password= adminpassword
or
web.config
<identity impersonate= "true "/>
or
<identity impersonate= "true " userName= "administrator " password= "adminpass "/>

[解决办法]
UnauthorizedAccessException: 存取被拒。
===========
您必须在域中有适当的权限才能创建用户和邮箱。通常情况下,要在一个基于 Windows 2000 的域中创建一个启用了邮箱的用户,您必须是该域的 Windows 2000 域管理员组成员。

参照:
如何使用 Visual C# 创建一个启用了邮箱的收件人
本文分步介绍了如何使用 System.DirectoryServices 命名空间和 CDO for Exchange Management (CDOEXM) 创建一个启用了邮箱的用户。

http://support.microsoft.com/kb/313114/zh-cn

热点排行