0

以下は、私の ASP.NET Web サイトの背後にあるページの 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>

これを修正する方法について、誰かが光を当てることができますか。ティア

4

1 に答える 1