Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding the stacktrace for an exception returned by a asp.net WebMethod?

I am using methods with the Attribute [WebMethod] in my aspx pages. I don't use any asp.net ajax but jQuery to call these methods and return objects in JSON. This all works fine.

Next I added an authorization check inside the webMethod, if the current user doesn't have access to the feature I need to let the calling JavaScript know.

So I am throwing an AccessViolationException exception which can then be parsed by the OnError callback function in JavaScript. This works too but the exception includes the full StackTrace and I don't want to make this available to the calling client.

What other ways I could use to return an "Access Denied" to the client when the WebMethod returns a business object?

I'm using ASP.Net 3.5SP1 and jQuery 1.32

like image 644
Peter Hahndorf Avatar asked Sep 05 '25 03:09

Peter Hahndorf


1 Answers

You can also add a:

customErrors mode="On"/

in your web.config, this will cut away the stack trace and leave you only the exception message

like image 198
Ludovico Avatar answered Sep 09 '25 00:09

Ludovico