如何阅读与.NET的ASP.NET内部服务器错误描述? [英] How to read an ASP.NET internal server error description with .NET?

查看:142
本文介绍了如何阅读与.NET的ASP.NET内部服务器错误描述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看哪,code:

using (var client = new WebClient())
{
    try
    {
        var bytesReceived = client.UploadData("http://localhost", bytesToPost);
        var response = client.Encoding.GetString(bytesReceived);
    }
    catch (Exception ex)
    {
    }
}

我收到此HTTP 500内部服务器错误时,UploadData方法被调用。但我看不到错误说明任何地方的EX的对象,而调试。我该如何重写这个code,所以我可以读取错误说明?

I am getting this HTTP 500 internal server error when the UploadData method is called. But I can't see the error description anywhere in the "ex" object while debugging. How do I rewrite this code so I can read the error description?

推荐答案

Web服务器通常返回错误页面,更多详细资料(HTML或根据服务器的纯文本)。您可以通过捕获 WebException 和阅读从响应属性中的响应流抓住这一点。

Web servers often return an error page with more details (either HTML or plain text depending on the server). You can grab this by catching WebException and reading the response stream from its Response property.

这篇关于如何阅读与.NET的ASP.NET内部服务器错误描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆