When any exception occurs on the ASP.MVC server side code, I would like to take the entire stack trace of the exception and place in the ViewData and returns to the client. For example:
try
{
//some code
}
catch (SomeException e)
{
ViewData["exceptionStack"] = e.StackTrace;
}
The JavaScript on the client side would just take the string in the ViewData and display it. For example:
<script type="text/javascript">
var exceptionStack = '<%= ViewData["exceptionStack"] %>';
</script>
The problem is how I can ensure, either via regex or other means, either on the server side using C# or on the client that the JavaScript variable exceptionStack would NOT contain any illegal character, so that when I do:
$('#someElement').text(exceptionStack);
or
$('#someElement').html(exceptionStack);
there won't be any error.