下面是我的 ASP.NET 网站后面页面中的 C# 代码。此代码工作正常(在按钮单击时执行),并在我在我的机器上调试时带回它需要带回页面上的 div 的内容。
protected void btnVctn_Click(object sender, EventArgs e)
{
Label1.Visible = true;
btnCloseVactn.Visible = true;
ExchangeService exchangeService = new ExchangeService();
exchangeService.Url = new Uri("https://mymailserviceurl/ews/exchange.asmx");
Folder myPublicFoldersRoot = Folder.Bind(exchangeService, WellKnownFolderName.PublicFoldersRoot);
string myPublicFolderPath = @"IT Services\ITServicesOutofOfficeCalendar";
string[] folderPath = myPublicFolderPath.Split('\\');
FolderId fId = myPublicFoldersRoot.Id;
foreach (string subFolderName in folderPath)
{
fId = FindPublicFolder(exchangeService, fId, subFolderName);
if (fId == null)
{
Label1.Text = "ERROR: Can't find public folder {0} " + myPublicFolderPath;
}
}
Folder folderFound = Folder.Bind(exchangeService, fId);
if (String.Compare(folderFound.FolderClass, "IPF.Appointment", StringComparison.Ordinal) != 0)
{
Label1.Text = "ERROR: Public folder {0} is not a Calendar " + myPublicFolderPath;
}
CalendarFolder AK_Calendar = CalendarFolder.Bind(exchangeService, fId, BasePropertySet.FirstClassProperties);
FindItemsResults<Appointment> AK_appointments = AK_Calendar.FindAppointments(new CalendarView(DateTime.Now, DateTime.Now.AddDays(10)));
string rString = string.Empty;
foreach (Appointment AK_appoint in AK_appointments)
{
rString += AK_appoint.Subject + "<br/> Start Date: " + AK_appoint.Start + "<br/>End Date: " + AK_appoint.End + "<br/>";
}
Label1.Text = rString;
ClientScript.RegisterStartupScript(this.GetType(), "hash", "location.hash = '#dvWorkQueue';", true);
}
public static FolderId FindPublicFolder(ExchangeService myService, FolderId baseFolderId,string folderName)
{
FolderView folderView = new FolderView(100, 0);
folderView.OffsetBasePoint = OffsetBasePoint.Beginning;
folderView.PropertySet = new PropertySet(FolderSchema.DisplayName, FolderSchema.Id);
FindFoldersResults folderResults;
do
{
folderResults = myService.FindFolders(baseFolderId, folderView);
foreach (Folder folder in folderResults)
if (String.Compare(folder.DisplayName, folderName, StringComparison.OrdinalIgnoreCase) == 0)
return folder.Id;
if (folderResults.NextPageOffset.HasValue)
folderView.Offset = folderResults.NextPageOffset.Value;
}
while (folderResults.MoreAvailable);
return null;
}
当我在生产 IIS 服务器上部署站点时,虽然加载了 aspx 页面,但当我单击“btnVctn”按钮时,它会出错说
为了访问公用文件夹,有效的呼叫者必须有一个邮箱。说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息: > Microsoft.Exchange.WebServices.Data.ServiceResponseException:为了访问公用文件夹,有效的调用者必须有一个邮箱。
源错误:第 47 行:文件夹 myPublicFoldersRoot = Folder.Bind(exchangeService, WellKnownFolderName.PublicFoldersRoot);
这是 web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<connectionStrings>
<add name="Databasename" connectionString="Data Source=mysource;Initial Catalog=Data;Persist Security Info=True;User ID=userid;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off" />
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>
任何人都可以阐明如何解决这个问题。TIA