By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,082 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"akhare1" <ak*****@my-deja.com> wrote in message
news:20**************************@posting.google.c om...
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

Nov 18 '05 #2

P: n/a
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message news:<uF**************@tk2msftngp13.phx.gbl>...
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
Nov 18 '05 #3

P: n/a
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message news:<uF**************@tk2msftngp13.phx.gbl>...
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
Nov 18 '05 #4

P: n/a
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.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
"akhare1" <ak*****@my-deja.com> wrote in message
news:20**************************@posting.google.c om...
"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:<uF**************@tk2msftngp13.phx.gbl>...
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

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.