当我在开发工具的控制台窗口中引入脚本时,就会出现 ASP.NET 错误消息
脚本:
for(var i = 0;i < 5;i++)
{
document.cookie = i+"="+"a".repeat(4000)
};
frame=document.createElement("iframe");
frame.src ="/";
document.body.appendChild(frame);
错误信息:
403 - 禁止:访问被拒绝。
您无权使用您提供的凭据查看此目录或页面。
我想显示非 ASP.NET 消息(如下所示)而不是此 ASP.NET 系统错误消息。
示例:
要实现此目的,您需要在设置 ASPX 错误页面后使用这两种方法之一创建自定义页面。
1- 在 Web.config 文件中,定义自定义错误处理以将特定 HTTP 错误代码路由到自定义错误页面
<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="ErrorPage.aspx">
<error statusCode="404" redirect="404Page.aspx" />
</customErrors>
</system.web>
</configuration>
2- 通过处理 Global.asax 文件中的 Application_Error 事件中的错误来实现全局错误处理:
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
Response.Redirect("~/ErrorPage.aspx");
}