【发布时间】:2016-09-13 23:28:24
【问题描述】:
我正在使用下面的代码来捕获 HttpRequestValidationException。 但问题是它导航到不同的页面。
我想在用户输入信息并单击提交按钮的同一页面上显示“无效输入”错误消息。
protected void Application_Error(object sender, EventArgs e)
{
var context = HttpContext.Current;
var exception = context.Server.GetLastError();
if (exception is HttpRequestValidationException)
{
Response.Clear();
Response.StatusCode = 200;
Response.Write(@"<html><head></head><body>Invalid Input</body></html>");
Response.End();
return;
}
}
【问题讨论】:
-
你在使用 ASP.NET MVC 吗?
标签: c# asp.net-mvc error-handling