我想从我的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中运行时效果很好。请指点