我正在做一個家庭項目,開始非常容易(並不總是發生?),然後採取了令人討厭的權限轉向。無法將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.
我已經通過嘗試改變權限資源管理器在網站上,但沒有運氣。
任何想法?
除非我做了一些可怕的錯誤,我也嘗試過,但沒有成功。在IIS管理器中,轉至應用程序池 - >池上的高級設置 - >過程模型 - >標識。它使用NetworkService內置帳戶,但將其更改爲有權訪問的自定義帳戶。 – Anjisan 2009-02-25 01:45:55
之後你是否重新啓動iis? – 2009-02-25 01:50:43