c# - 重定向到错误页面并显示用户友好错误

标签 c# asp.net error-handling

在我的应用程序中,我想重定向到错误页面。在错误页面上有一个标签,它将显示一个用户友好的错误。我可以重定向到页面。问题是将标签设置为用户友好错误。

if (xy.Count() >= 1)
{            
    foreach (var x in xy)
    {
        employeeEmploy.Add(x);
        Debug.WriteLine(x.employee_personal_id);
    }
}
else 
{
    Security.ErrorControl.displayErrorMsg = "Employee Employ currently doesn't have any persons inside";

    Debug.WriteLine(Security.ErrorControl.displayErrorMsg); // class that set and get the error message i want to display

    HttpContext.Current.Response.Redirect("ssperror.aspx"); // I am getting to redirect .. just need to set the label to the error message.

}

最佳答案

您可以在重定向时在查询字符串中传递错误消息(甚至更好的是表示消息ID的ID),因此最后一行是:

  HttpContext.Current.Response.Redirect("ssperror.aspx?err_id=4"); 

然后可以在ssperror.aspx中分析参数err_id,检索并在标签中显示错误消息:
if (Request.QueryString["err_id"] != null)
{
    lbl_error.text = retrieve_errormessage_from_code(Request.QueryString["err_id"]);
}

关于c# - 重定向到错误页面并显示用户友好错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16544240/

相关文章:

c# - 如何配置 log4net 以在 Debug模式下打印到控制台

jquery - 为什么这个js脚本在回发后在asp.net中不起作用?

c# - gridview 更新时确认消息

asp.net - ASP.Net 变量的范围

c# - 如何使我的应用程序处理几种不同情况下的错误?

python - 处理 IncompleteRead,URLError

C# - 从 mySQL 数据库获取数据时出错

c# - 有什么办法可以减少这两个 linq 查询中的重复

typescript - Aurelia Typescript http-fetch-client异步捕获不起作用

c# - Windows IoT 上的 Windows Universal App 中的屏幕键盘?