views:

342

answers:

1

I am trying to send an outlook appointment from my asp.net page and it works fine when i am running in my VS2008 IDE.But when i published this and configured as a virtual directory, While trying to execute the same, i am getting the below error.

 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

My code is as below

 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());

   }

  }

Can any one help me to solve this ? I am sure this is something with security . The above code works well when runs in VS 2008 IDE. Please advice

+1  A: 

See the error message:

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 , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

Either you need to impersonate the user making the Web request (in which case that user must have permissions for the server instance of Outlook) or you need to grant the ASP.NET process identity permissions to Outlook.

That said, neither solution is ideal, as Outlook is an interactive application and you probably don't want to be trying to interact with it from a server process. Consider using the Exchange API, or returning a .ics file, depending on what you're trying to achieve.

itowlson