Publishing Exception in SPS Web Parts


Assume that you have configured the SPS Site to be working under following conditions.

  • "NT AUTHORITY\Authenticated Users" users as Reader on the portal, 

  • Web.Config for the particular Portal is marked as <identity impersonate="true" />

And now a user who is part of the Network where the SPS Web is running logs in to the portal, and now this user is not part of the users from the machine where SPS Web Site is running, and an exception is generated in any of the WebParts, and you are using Microsoft's Exception Management Application Block to publish the Exception in the Event Viewer - then the exceptions which would be generated for this particular user can not be logged in to Event Viewer, basically the Exception block throws an Exception. The reason behind this scenario is that since we are doing impersonation with the current user, and to write in to Event Log the user should be having "Admin Access" on the machine. To avoid this issue following lines of code should be added in the Catch block.

try
{
}
catch(Exception e)
{
System.Security.Principal.WindowsImpersonationContext wic =
// make impersonation = false in the code.
System.Security.Principal.WindowsIdentity.Impersonate
(IntPtr.Zero);
// again roll back the Impersonation = true
ExceptionManager.Publish(e);
wic.Undo();
}

Basically what you are doing is doing is <identity impersonate="false"/> in the code for publishing exception, so the exception is published by the Exception Manager with the user under which the AppPool of the SPS WebSite is running. (Provided that the AppPool Identity is having "Admin Access" on the machine to Publish Exception in Event Viewer.)