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