从 IIS 获取 ERR_CONNECTION_RESET 而日志中没有信息
Getting ERR_CONNECTION_RESET from IIS with no information in logs
当我的 ASP.NET 服务器尝试回复错误时,我在 Chrome 中收到 ERR_CONNECTION_RESET
。
通常我可以通过查看日志文件找到有关服务器错误的信息,但那里什么也没有。
运行 对响应的调试器似乎显示一切正常,除了最后,Chrome 告诉我连接已重置。
下面是处理异常处理的代码:
try
{
...
}
catch (ArgumentException e)
{
Response.StatusCode = 400;
Response.StatusDescription = e.Message;
return new ContentResult {Content = "" };
}
Chrome 在控制台中显示 net::ERR_CONNECTION_RESET
。
使用 Fiddler,我收到错误消息 [Fiddler] ReadResponse() failed: The server did not return a complete response for this request. Server returned 0 bytes.
如果我在IIS中Enable Failed Request Tracing,打开生成的xml文件
GENERAL_FLUSH_RESPONSE_END
BytesSent
0
ErrorCode
The parameter is incorrect.
(0x80070057)
我花了几个小时尝试调试它,但运气不佳。
原来是这条线引起的:
Response.StatusDescription = e.Message;
当e.Message里面有一个换行符(\r\n
)序列时。
我可以用来修复此错误的两个选项是:
1. 将此行替换为:
Response.StatusDescription = e.Message.Replace("\r\n"," ");
2. 将catch块替换为
catch (ArgumentException e)
{
Response.StatusCode = 400;
return new ContentResult {Content = e.Message };
}
在尝试使用本地主机上的一些虚拟域并分配 SSL 证书后,我遇到了这个问题。为当前域选择 IIS 开发证书错误消失。
当我的 ASP.NET 服务器尝试回复错误时,我在 Chrome 中收到 ERR_CONNECTION_RESET
。
通常我可以通过查看日志文件找到有关服务器错误的信息,但那里什么也没有。
运行 对响应的调试器似乎显示一切正常,除了最后,Chrome 告诉我连接已重置。
下面是处理异常处理的代码:
try
{
...
}
catch (ArgumentException e)
{
Response.StatusCode = 400;
Response.StatusDescription = e.Message;
return new ContentResult {Content = "" };
}
Chrome 在控制台中显示 net::ERR_CONNECTION_RESET
。
使用 Fiddler,我收到错误消息 [Fiddler] ReadResponse() failed: The server did not return a complete response for this request. Server returned 0 bytes.
如果我在IIS中Enable Failed Request Tracing,打开生成的xml文件
GENERAL_FLUSH_RESPONSE_END
BytesSent
0
ErrorCode
The parameter is incorrect.
(0x80070057)
我花了几个小时尝试调试它,但运气不佳。
原来是这条线引起的:
Response.StatusDescription = e.Message;
当e.Message里面有一个换行符(\r\n
)序列时。
我可以用来修复此错误的两个选项是:
1. 将此行替换为:
Response.StatusDescription = e.Message.Replace("\r\n"," ");
2. 将catch块替换为
catch (ArgumentException e)
{
Response.StatusCode = 400;
return new ContentResult {Content = e.Message };
}
在尝试使用本地主机上的一些虚拟域并分配 SSL 证书后,我遇到了这个问题。为当前域选择 IIS 开发证书错误消失。