Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I didn't quite understand your problem at first. To avoid seeing the Stack Trace, you simply had have display <code>Server.GetLastError().Message</code>. On further examination I see that your problem is that exceptions are getting wrapped into a <em>HttpException</em>, and the Message from <em>HttpException</em> concatenates the method info with the original exception message.</p> <h2>Solution</h2> <p>In <em>web.config</em> you need to add a custom error section.</p> <pre><code>&lt;customErrors defaultRedirect="Error.aspx" mode="On" redirectMode="ResponseRewrite"&gt; </code></pre> <p>In <em>Error.aspx</em> you can do the following to check if it's an <em>HttpException</em>, and if so get the inner exception's message.</p> <pre><code>var ex = Server.GetLastError(); string message; if (ex != null) { message = ((ex is HttpException || ex is SoapException) &amp;&amp; ex.InnerException != null) ? ex.InnerException.Message : ex.Message; } else { message = "An error has occurred."; } Response.Write(message); </code></pre> <p>On your page you just want to show <strong>Server.GetLastError().Message</strong>.</p> <p>Here is the before and after for a divide by zero error:</p> <ul> <li><strong>Before</strong>: Default.aspx(4): error CS0020: Division by constant zero </li> <li><strong>After</strong>: Attempted to divide by zero. </li> </ul> <p>For <em>SoapException</em> to actually have the InnerException property not be null, then you need to throw a SoapException with the actual exception inside.</p> <p>Here are some links from MSDN regarding the customErrors section and error handling:</p> <ul> <li><a href="http://msdn.microsoft.com/en-us/library/vstudio/h0hfz6fc%28v=vs.100%29.aspx" rel="nofollow">customErrors Element</a></li> <li><a href="http://msdn.microsoft.com/en-us/library/bb397417%28v=vs.100%29.aspx" rel="nofollow">Complete Example for Error Handlers</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload