C#:作为站点发布时从C#程序访问Outlook时的安全问题

时间:2009-12-24 05:15:33

标签: c# security iis outlook

我正在尝试从我的asp.net页面发送Outlook预约,当我在我的VS2008 IDE中运行时它工作正常。但是当我发布这个并配置为虚拟目录时,在尝试执行相同的时候,我我收到以下错误。

 Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005.
 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: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005.

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 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:

 An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

 [UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80070005.]
 _Default.SendAppointment() +42
 _Default.Page_Load(Object sender, EventArgs e) +13
 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
 System.Web.UI.Control.OnLoad(EventArgs e) +99
 System.Web.UI.Control.LoadRecursive() +50
 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

我的代码如下

 using System.Reflection;
 using OutLook = Microsoft.Office.Interop.Outlook;
 using System.Runtime.InteropServices;





 private void SendAppointment()
  {

   try

   {

       OutLook.Application app = null;

       OutLook.AppointmentItem appt = null;

       app = new OutLook.Application();

       appt = (OutLook.AppointmentItem)app.CreateItem(OutLook.OlItemType.olAppointmentItem);



       appt.Subject = "Test subject";

       appt.Body = "Test";

       appt.Location = "TBD";

       appt.Start = DateTime.Today;

       appt.End = DateTime.Today.AddDays(1);

       appt.ReminderSet = true;

       appt.ReminderMinutesBeforeStart = 15;

       appt.Importance = OutLook.OlImportance.olImportanceHigh;

       appt.BusyStatus = OutLook.OlBusyStatus.olBusy;

       appt.Save();

       appt.MeetingStatus = OutLook.OlMeetingStatus.olMeeting;

       appt.RequiredAttendees = "rssabu@company.com";

       appt.Send();

       Response.Write("Done");

   }

   catch (COMException ex)

   {

       Response.Write(ex.ToString());

   }

  }

任何人都可以帮我解决这个问题吗?我确信这是有安全感的。在VS 2008 IDE中运行时,上面的代码运行良好。请建议

2 个答案:

答案 0 :(得分:1)

请参阅错误消息:

  

ASP.NET无权访问   请求的资源。考虑   授予对资源的访问权限   到ASP.NET请求标识。   ASP.NET具有基本进程标识   (通常是IIS 5上的{MACHINE} \ ASPNET   或IIS 6上的网络服务)   如果申请不是,则使用   冒充。如果申请是   冒充通过,身份   将是匿名用户(通常是   IUSR_MACHINENAME)或经过身份验证的   请求用户。

您需要模拟发出Web请求的用户(在这种情况下,用户必须具有Outlook服务器实例的权限),或者您需要向Outlook授予ASP.NET进程标识权限。

也就是说,这两种解决方案都不理想,因为Outlook是一个交互式应用程序,您可能不希望尝试从服务器进程与它进行交互。请考虑使用Exchange API或返回.ics文件,具体取决于您要实现的目标。

答案 1 :(得分:0)

Web配置:

转到DcomConfig: 然后转到以下组件属性----&gt;身份标签 1.Microsoft Outlook 2.Microsoft Outlook命令按钮控件 3.Outlook消息附件 确保选中“交互式用户”。

然后转到安全标签并添加并完全依照网络服务,Intractive,ASP。