views:

390

answers:

2

My ASP.NET 2.0 web app includes a web service, which throws various exceptions along with custom error messages (e.g. "You do not have access to this item" etc.). These are shown on screen, in a ASP.NET AJAX callback handler.

The rest of the app is covered by some custom error pages, specified in the usual way in web.config.

<customErrors mode="RemoteOnly" defaultRedirect="Error.html">
      <error statusCode="404" redirect="NotFound.html" />
      <error statusCode="403" redirect="NoAccess.html" />
</customErrors>

My problem is if I have customErrors enabled in web.config, I lose my error messages returned from the web service - instead they are replaced with

"There was an error processing the request" - which isn't very useful for either me or the users.

Is there a way to turn off custom errors for just the web service?

+1  A: 

Put your web service into separate directory and put additional web.config file in this directory. Each directory can have it own web.config containing settings of this directory (and directories inside this directory).

smok1
Perfect - thanks smok1 :)
Phil Jenkins
No problem! The only reason is that you probaly will have now to update two web.config files when changing settings (for example when you decide to change connection string, or sth like that) to your web application.
smok1
@smok1: You only need to have the CustomErrors element in the nested .config file - there's no need to add anything you don't want to change.
Zhaph - Ben Duguid
@Zhaph - Ben Duguid - yes, you are right. The only reason for having all in your webconfig is when you do note have a single root directory.
smok1
+2  A: 

Yes, the custom errors element

can be defined at any level in the application file hierarchy.

So provided your WebService is in a folder you can add a web.config for that folder and turn them off.

Zhaph - Ben Duguid
I'll vote this up too - thanks for your help
Phil Jenkins