Exchange 401 未经授权

发布于 2024-09-06 13:09:45 字数 1590 浏览 7 评论 0原文

我正在尝试连接到我们的 Exchange 2007 服务器。我已经放置了很多异常处理来捕获任何错误并将它们放入应用程序日志中。首先,我有一个函数,确保用户可以使用提供的凭据访问交换服务:

public bool Logon()
{
    string pwd = /*Get password*/;

    try
    {
        service.Credentials = new WebCredentials(
            username + "@our.domain", pwd);

        service.FindItems(WellKnownFolderName.Outbox, new ItemView(1));
    }
    catch (Exception)
    {
        return false;
    }
    return true;
}

如果此函数返回 false,则会在应用程序日志中放置一个条目,报告用户登录失败,然后进程终止。

如果该函数成功,那么我们将调用该函数;它获取用户在接下来的 10 分钟内开始的所有约会:

protected List GetFutureAppointments()
{
    try
    {
        SearchFilter.IsGreaterThanOrEqualTo startTime =
            new SearchFilter.IsGreaterThanOrEqualTo(
                AppointmentSchema.Start, DateTime.Now);

        SearchFilter.IsLessThanOrEqualTo endTime =
                new SearchFilter.IsLessThanOrEqualTo(
                    AppointmentSchema.Start, DateTime.Now.AddMinutes(10));

        SearchFilter filter = 
            new SearchFilter.SearchFilterCollection(LogicalOperator.And,
                new SearchFilter[] { startTime, endTime });

        FindItemsResults results =  
            service.FindItems(
                WellKnownFolderName.Calendar, filter, new ItemView(10));

        return new List(results.Items);
    }
    catch (Exception e)
    {
        Utilities.LogException(e);
        return null;
    }
}

如您所见,该函数将捕获所有异常并记录它们。日志中显示请求失败。远程服务器返回错误:(401) 未经授权。 堆栈跟踪指向 service.FindItems() 函数。

所以我有点困惑,可能对交换或网络服务或其他什么了解不够。登录函数返回 true,但随后授权失败。有什么建议吗?

I am trying to connect to our exchange 2007 server. I have placed lots of exception handling to catch any errors and put them in the application log. Firstly, I have a function which ensures that a user can access the exchange service with the provided credentials:


public bool Logon()
{
    string pwd = /*Get password*/;

    try
    {
        service.Credentials = new WebCredentials(
            username + "@our.domain", pwd);

        service.FindItems(WellKnownFolderName.Outbox, new ItemView(1));
    }
    catch (Exception)
    {
        return false;
    }
    return true;
}

If this function returns false, an entry is placed in the application log reporting that the user failed to login, the process then terminates.

If the function succeeds, then somewhere down the track we call this function; it gets all appointments for the user which are starting in the next 10 minutes:


protected List GetFutureAppointments()
{
    try
    {
        SearchFilter.IsGreaterThanOrEqualTo startTime =
            new SearchFilter.IsGreaterThanOrEqualTo(
                AppointmentSchema.Start, DateTime.Now);

        SearchFilter.IsLessThanOrEqualTo endTime =
                new SearchFilter.IsLessThanOrEqualTo(
                    AppointmentSchema.Start, DateTime.Now.AddMinutes(10));

        SearchFilter filter = 
            new SearchFilter.SearchFilterCollection(LogicalOperator.And,
                new SearchFilter[] { startTime, endTime });

        FindItemsResults results =  
            service.FindItems(
                WellKnownFolderName.Calendar, filter, new ItemView(10));

        return new List(results.Items);
    }
    catch (Exception e)
    {
        Utilities.LogException(e);
        return null;
    }
}

As you can see, the function will catch all exceptions and log them. Showing up in the log is Request failed. The remote server returned an error: (401) Unauthorized. The stack trace points to the service.FindItems() function.

So I'm a little confused and probably don't know enough about exchange or web services or whatever. The logon function is returning true, but then authorization fails later on. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-09-13 13:09:45

您的凭据是否可能允许您访问发件箱,但不能访问日历?

It is possible that your credentials give you access to the Outbox but not the the Calendar?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文