0

I want to show the Custom Errors in error.aspx page when any error occur. Its redirecting to error.aspx when error happens. But not showing the message.

I set web.config like

<customErrors mode="On" defaultRedirect="/error.aspx" redirectMode="ResponseRewrite">
  <error statusCode="404" redirect="/notfound.aspx" /></customErrors>

Is there any way to show the error message in error.aspx page.

1 Answer 1

0

You can call the GetLastError() and show the error.

// Get the last error from the server
var ex = Server.GetLastError();

if (null != ex)
{
   // get and render here the error, there are a lot more info to see.
   txtLiteral.Text = ex.Message;
}

// and clear the error from the server
Server.ClearError();

But I suggest to write it down to a log, and not show it to your users. Also locally there is not reason for custom page, leave it as they are to see the errors.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok. But where i should write this code, in error.aspx??
@Vahid in notfound.aspx that you ask for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.