使用 MVC 处理 WCF Web 配置错误?
我打算在 Global.asax 中使用以下 Application_Error() 处理:
protected void Application_Error()
{
Exception exception = Server.GetLastError();
Response.Clear();
HttpException httpException = exception as HttpException;
if (httpException != null)
{
string action;
switch (httpException.GetHttpCode())
{
case 404:
// page not found
action = "HttpError404";
break;
case 500:
// server error
action = "HttpError500";
break;
default:
action = "General";
break;
}
// clear error on server
Server.ClearError();
Response.Redirect(String.Format("~/Error/{0}/?message={1}", action, exception.Message));
}
}
但是,问题是我无法捕获此错误:
传入消息的最大消息大小配额 (100000) 已调整 超过了。要增加配额,请使用 MaxReceivedMessageSize 适当的绑定元素上的属性。
当我将 web.config 值设置为低时,就像它到达 Response.Clear() 时一样;调用时,我收到 HTTP 异常:
在此情况下无法做出响应。
我怎样才能解决这个问题来处理所有异常?
谢谢。
I was about to use the following Application_Error() handling in my Global.asax:
protected void Application_Error()
{
Exception exception = Server.GetLastError();
Response.Clear();
HttpException httpException = exception as HttpException;
if (httpException != null)
{
string action;
switch (httpException.GetHttpCode())
{
case 404:
// page not found
action = "HttpError404";
break;
case 500:
// server error
action = "HttpError500";
break;
default:
action = "General";
break;
}
// clear error on server
Server.ClearError();
Response.Redirect(String.Format("~/Error/{0}/?message={1}", action, exception.Message));
}
}
However, the issue was that I couldn't trap this error:
The maximum message size quota for incoming messages (100000) has been
exceeded. To increase the quota, use the MaxReceivedMessageSize
property on the appropriate binding element.
When I had the web.config value set to low, as when it got to the Response.Clear(); call, I get an HTTP exception:
Response is not available in this context.
How can I get around this to handle all exceptions?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论