C#代码不用域名访问交换服务器,可以吗?
我正在开发一个 Web 应用程序来访问 Exchange Server 2010 以从服务器获取电子邮件。问题是,我们没有该服务器的域名。我所知道的是它的IP地址。是否可以使用 Exchange Web Service 访问服务器?这是我的代码:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010); service.Credentials=new NetworkCredential("StevenZack","123456","208.243.49.20"); //service.AutodiscoverUrl("[电子邮件受保护]"); service.Url = new Uri("https://208.243.49.20/EWS/Exchange.asmx"); FindItemsResults findResults = service.FindItems( WellKnownFolderName.Inbox, 新的 ItemView(10));
foreach (Item item in findResults.Items)
{
div_email.InnerHtml = item.Subject + "<br />";
}
出现错误“根据验证程序,远程证书无效”
如何处理这种情况?有什么想法吗?谢谢您的宝贵时间!
I'm working on a web application to access exchange server 2010 to get emails from the server. The question is, we don't have domain name for this server. What I know is it's IP address. Is that possible to use Exchange Web Service to access the server? This is my code:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials=new NetworkCredential("StevenZack","123456","208.243.49.20");
//service.AutodiscoverUrl("[email protected]");
service.Url = new Uri("https://208.243.49.20/EWS/Exchange.asmx");
FindItemsResults findResults = service.FindItems(
WellKnownFolderName.Inbox,
new ItemView(10));
foreach (Item item in findResults.Items)
{
div_email.InnerHtml = item.Subject + "<br />";
}
It comes out with an error of "The remote certificate is invalid according to the validation procedure"
How to deal with this situation? Any idea? Thank you for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过设置 ServicePointManager.ServerCertificateValidationCallback 委托可以避免 SSL 警告(请参阅 http://www.infinitec.de/post/2008/11/26/ExchangeWebServices-WebDAV-and-untrusted-server-certificates.aspx)。
但这可能对你没有帮助。如果指定 208.243.49.20,则您将使用计算机本地帐户而不是域帐户连接到计算机。
您可以使用集成身份验证吗?您可以冒充用户并直接使用他的凭据。这样,用户就不必再次输入其凭据。请注意,如果您的 Web 应用程序与 Exchange 服务器驻留在不同的服务器上,则需要配置 Kerberos。
The SSL warning can be avoiding by setting the ServicePointManager.ServerCertificateValidationCallback delegate (see http://www.infinitec.de/post/2008/11/26/ExchangeWebServices-WebDAV-and-untrusted-server-certificates.aspx).
But this probably won't help you. If you specify 208.243.49.20 you are connecting to the machine using a machine-local account instead of your domain account.
Can you, by any chance, use integrated authentication? You could just impersonate the user and use his credential directly. This way, the user doesn't have to enter his credentials again. Note that you would need to configure Kerberos if your web application resides on a different server as your Exchange server.