上个星期六的时候(2月14日,情人节),来公司加班,把DearBook的程序从一台服务器搬到另外的两台服务器,在重新配置程序的时候,发现我写的发送email的函数,在服务进程里面调用没有问题,在ASP.net页面调用就有问题,为了这个问题,查了一下午,都没有解决,后来把发送Email的那部分,全部部署到服务程序里面。才算完成痛苦的情人节加班。
对这个问题的原因一直怀疑是ASPNet帐户没有权限造成的,在网上找了不少资料,但是网上提供的方案,大多是给了ASP.net更多的权限,我不想给ASP.net更多的权限,就去动力营问微软技术工程师。以下是我整理自网上以及微软动力营的解决方案。
错误表现:Could Not Access CDO.Message Error
The transport lost its connection to the server.
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.Runtime.InteropServices.COMException: The transport lost its connection to the server.
[HttpException (0x80004005): Could not access 'CDO.Message' object.]
原因:ASPNet用户没有对CDO.Message 的访问权限。
解决方案:
方案一:
try the steps below to grant the ASPNET the property permission.
1. Start -> Control Panel -> Administrative Tools -> Component Services.
2. Look for the desired COM component and add the ASPNET'user to the roles.
这种方案需要Com组件是进程外的组件,CDO组件是进程内的组件,因此无法使用。
方案二:
you can launch the aspnet_wp.exe with an account which has enough permission. Please try these steps:
1. Find machine.config (usually under directory>\Microsoft.NET\Framework\v1.0.3705\CONFIG) and edit the
section. Change the "userName" attribute value to "SYSTEM".
2. Edit the "web.config" file in the ASP .NET project. Add the following
line:
password=password> />
The user name you provide here need to have the permission to call the CDO
component.
3. Restart the aspnet_wp.exe. You can also kill it in Task Manager. Then
aspnet_wp will start using SYSTEM account.
You also can impersonate ASPNET as a user having permission. For more
information about ASP.NET Impersonation please see:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconaspnetimpersonation.asp
http://support.microsoft.com/default.aspx?scid=KB;en-us;306158
这个方案给了ASPNet帐户较大的权限。
以上两个资料参考来源:
http://groups.google.com/groups?q=CDO.Message+SmtpMail.Send(&hl=zh-CN&lr=&ie=UTF-8&oe=UTF-8&selm=aLZQAD45CHA.1536%40cpmsftngxa08.phx.gbl&rnum=3
方案三:
CDO组件是进程内的组件,因此要建立进程内的组建,只需要NTFS权限和对注册表的访问。无需对组建服务进行配置。
您可以尝试按如下步骤操作:
1。给ASPNET 账户访问HKCR/TypeLib/{cdo clsid} (Microsoft CDO for Windows 2000-CDOSYS)的权限,这样ASPNET 账户就可以调用CREATEOBJECT ("CDO.Message")
(cdo clsid可以从HKCR/CLSID下获得)
2。 给ASPNET账户添加如下权限:
给如下目录添加NTFS文件权限:C:\Inetpub\mailroot\pickup folder
您可以参考如下文章:
XIMS: Minimum NTFS Permissions Required to Use CDONTS
http://support.microsoft.com/?id=260985
这个方案给了ASPNet帐户够用的权限。