2009-12-24 23 views
0

我想从我的asp.net页面发送Outlook约会,并且在VS2008 IDE中运行时它工作正常。但是当我发布此并配置为虚拟目录,虽然试图执行相同的操作,但我得到了下面的错误。C#:从C#程序作为站点发布时访问Outlook时的安全问题

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 = "[email protected]"; 

     appt.Send(); 

     Response.Write("Done"); 

    } 

    catch (COMException ex) 

    { 

     Response.Write(ex.ToString()); 

    } 

    } 

任何一个可以帮助我解决这个问题?我相信这是安全的。上述代码在VS 2008 IDE中运行时效果很好。请指点

回答

1

看到错误消息:

ASP.NET未被授权的访问 所请求的资源。考虑 将对资源 的访问权限授予ASP.NET请求标识。 ASP.NET具有基部进程标识 (通常{MACHINE} \ ASPNET IIS 5上 或IIS 6上网络服务),其是用于 如果应用程序是不 冒充。如果应用程序是 模拟通过,身份 将是匿名用户(通常为 IUSR_MACHINENAME)或验证 请求用户。

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

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

0

Web配置:

转到DcomConfig: 然后转到以下组件性质鉴别仪表---->标识选项卡 1.Microsoft展望 2.Microsoft Outlook命令按钮控件 3.Outlook邮件附件 确保选中“交互式用户”。

然后转到安全选项卡并添加并完全认可网络服务,Intractive,ASP。