C# Source Code: Configuring remoting custom errors
[
Home
|
Contents
|
Search
|
Reply
| Previous |
Next
]
C# Source Code
Configuring remoting custom errors
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, May 11, 2004
Hits:
1590
Category:
Unspecified
Article:
The customErrors element of system.runtime.remoting indicates whether the server channels in this application domain return filtered or complete exception information to local or remote callers. Possible values are: "Off" All callers receive complete exception information. "On" All callers receive filtered exception information. "RemoteOnly" Local callers receive complete exception information; remote callers receive filtered exception information. Note that the values are case sensative and are incorrectly quoted on the MS web site (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gnconcustomerrorselement.asp) as being lower case values! Below are two methods of configuring the customErrors property. The first involves adding XML to you app.config and the second uses reflection to set the property programatically: Method 1 (XML Config file):
system.runtime.remoting>
PLEASE NOTE - YOU MUST CORRECTLY CAPITALISE "Off" ("off" will NOT WORK!!!) Method 2 (Reflection): //Get the assembly that hosts System.Runtime.Remoting.RemoteConfiguration System.Reflection.Assembly remoting = System.Reflection.Assembly.GetAssembly(typeof(System.Runtime.Remoting.RemotingConfiguration)); //Next get the internal static RemotingConfigHandler class Type remotingConfigHandler = remoting.GetType("System.Runtime.Remoting.RemotingConfigHandler"); //Get the CustomErrorsModes enum (used to set the _errorMode) Type customErrorsModes = remoting.GetType("System.Runtime.Remoting.CustomErrorsModes"); //Get the (non public static) error mode field FieldInfo errorMode = remotingConfigHandler.GetField("_errorMode", BindingFlags.Static | BindingFlags.NonPublic); //Get the "off" member of the enum FieldInfo mode = customErrorsModes.GetField("Off"); //Set the error mode value to off errorMode.SetValue(null, mode.GetValue(null));
Terms and Conditions
Support this site
Download a trial version of the best FTP application on the internet