Intermittent failure to read registry key in ASP.NET application...

A

akhare1

OK, before I start, let me clarify a few things here. This is not the
run of the mill failure to read a registry key while trying to write
to the Event Log.

Here's our setup:

a) IIS 6.0 server w/ SharePoint installed
b) ASP.NET application w/ NTLM authentication running under an account
(application pool) with ADMIN privileges on the local box.
c) We are NOT using impersonation

We have a registry key under HKLM that can be accessed only by the
account that's running the ASP.NET account. However, occasionally we
see a failure that looks as follows:

Unexpected exception Requested registry access is not allowed.
encountered at at Microsoft.Win32.RegistryKey.OpenSubKey(String
name, Boolean
writable)

What's really surprising is that fact that the error is intermittent,
i.e., we do not see that failure all the time. Furthermore, the error
seems go away on its own at times.

Clearly, it's not a question of privilege because our ASP.NET worker
process is running with full Admin rights.

Atul
 
A

Alvin Bruney [MVP]

registry access can be flakey, i had an article about this somewhere can't
find it at the moment.

if you really intend to go after this problem you will need to monitor
access per registry key
regmon utility from sysinternals.com comes to mind. absolutely potent stuff
for monitoring all sorts of registry behavior.

so in a nutshell you wire it up to watch your particular key and wait for
the bug to pop. When it pops, catch it, see what regmon says caused the
problem and kill it dead. It's not that easy though, in fact it is down
right nasty to go after reg issues but that is your general direction. Let
me know what you find out.
 
A

akhare1

Alvin Bruney said:
registry access can be flakey, i had an article about this somewhere can't
find it at the moment.

if you really intend to go after this problem you will need to monitor
access per registry key
regmon utility from sysinternals.com comes to mind. absolutely potent stuff
for monitoring all sorts of registry behavior.
<snip>
I am curious to know what you mean by flaky registry access. Is this a
documented bug in the Win32 subsystem (I am pretty sure
Registry.OpenKey calls the underlying Win32 API)?

We have run Regmon on the system before, but didn't notice anything,
but we'll leave it running and hope that the failure occurrs. Also,
what's interesting is we have (failure) auditing turned on for the
registry key, but we haven't noticed a single audit entry.

Atul
 
A

akhare1

Alvin Bruney said:
registry access can be flakey, i had an article about this somewhere can't
find it at the moment.

if you really intend to go after this problem you will need to monitor
access per registry key
regmon utility from sysinternals.com comes to mind. absolutely potent stuff
for monitoring all sorts of registry behavior.
BTW, thanks for your suggestions. I have examined the code many times
and simply cannot find anything wrong with it. What's even more
interesting is that we read the registry key once and cache it. The
code looks something like this:

//Obtain AppDomain wide lock...
lock(typeof(MyLockObject))
{
if(MyRegValue != null)
{
try
{
//Open registry key, read value and set MyRegValue

}
catch(Exception Ex)
{
//Log details....
}
finally
{
//if(RegistryHandle != null)
//Close Registry Handle...
}
}
}
As you can see we are ensuring that the registry handle is always
closed so that can't be a factor. Also, we obtain an AppDomain wide
lock so multiple threads cannot be the reason either. ASP.NET does
create multiple AppDomains for the same applications to handle
requests if needed, but I don't see how it can possibly influence
reading of the key.

Atul
 
A

Alvin Bruney [MVP]

I've done some research on this but came up empty handed. your code is the
approach i would take as well. I meant flakey as in permissions errors every
now and again like what you are experiencing. I believe this one is at the
limits of my knowledge.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top