2009-02-25 15 views
1

我正在做一個家庭項目,開始非常容易(並不總是發生?),然後採取了令人討厭的權限轉向。無法將ASP.NET連接到IIS的Outlook,但可以通過Visual Studio

基本上,我有一個家庭內部網,我的個人電腦作爲家庭網絡服務器執行雙重任務。我正在運行Vista,所以我們正在談論IIS 7.

在Visual Studio中,此功能完美無缺。我有我的主頁查詢Outlook(2007)並顯示下幾次約會。我這樣做,

using Microsoft.Office.Interop.Outlook; 

//Be kind -- this is a work in progress 
public static string nextAppointment() 
{ 
    System.Text.StringBuilder returnString = new System.Text.StringBuilder(); 

     try 
     { 
      Application outlookApp = new ApplicationClass(); 
      NameSpace outlookNamespace = outlookApp.GetNamespace("MAPI"); 
      MAPIFolder theAppts = outlookNamespace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar); 

      List<AppointmentItem> todaysAppointments = new List<AppointmentItem>(); 
      TimeSpan oneday = new TimeSpan(24, 0, 0); 
      DateTime today = DateTime.Today; 
      DateTime yesterday = today.Subtract(oneday); 
      DateTime tomorrow = today.Add(oneday); 

      foreach (AppointmentItem someAppt in theAppts.Items) 
      { 
       if (someAppt.Start > yesterday && someAppt.Start < tomorrow) 
       { 
        todaysAppointments.Add(someAppt); 
       } 
      } 

      foreach (AppointmentItem todayAppts in todaysAppointments) 
      { 
       returnString.Append(todayAppts.Start.ToShortTimeString() + " -- " + todayAppts.Subject + "<br />"); 
      } 
     } 
     catch (System.Exception ex) 
     { 
      //TO-DO: Add some real handling 
      returnString.Append("Cannot access calendar"); 
     } 


     return returnString.ToString(); 
} 

這段代碼只是一個正在進行的工作,但你明白了。它會在24小時內查看我有哪些日曆活動,然後將它們添加到我最終在網頁上寫出的字符串中。當我在Visual Studio中調試它時,它通過ASP.NET Development Studio運行良好。要自信,我採取相同的代碼和運行在IIS上它都在家裏享受,我得到錯誤(當我不明白我的除外),

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 , 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.

我已經通過嘗試改變權限資源管理器在網站上,但沒有運氣。

任何想法?

回答

0

結束了被別的東西完全:

2倍步驟 - (1)輸入的身份憑證來冒充要麼在web.config中或通過IIS和 (2)給同一用戶在寫訪問Windows \ Microsoft.NET \ Framework \ v2.0.50727 \臨時ASP.NET文件

編輯池設置沒有效果,因爲它結果。我可以返回並將該池置於NetworkService下,這並不重要。

感謝您的幫助!非常感激!!它絕對把我放在正確的軌道上

1

嘗試在有權訪問的用戶(例如域用戶)下運行Web應用程序的應用程序池。

+0

除非我做了一些可怕的錯誤,我也嘗試過,但沒有成功。在IIS管理器中,轉至應用程序池 - >池上的高級設置 - >過程模型 - >標識。它使用NetworkService內置帳戶,但將其更改爲有權訪問的自定義帳戶。 – Anjisan 2009-02-25 01:45:55

+0

之後你是否重新啓動iis? – 2009-02-25 01:50:43

1

我發現IIS身份驗證永遠混淆。

顯然,問題在於您的Web應用程序的安全上下文不允許它訪問您的Outlook日曆。不幸的是,有幾個地方你可以進行調整,他們都需要一起玩。 爲了讓別人弄清楚什麼出了問題,你需要提供關於你的應用程序(web config)和IIS設置的更多信息。

或者,或者看看this article,我發現它非常有用。也許這會幫助你自己想出來。

嘗試啓用模擬,無論是在web.config中還是在代碼中,關閉匿名訪問,並且如果Integrated不起作用,請爲您的應用程序池嘗試Classic管道。

相關問題