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

Problems accessing registry keys within ASP.NET application

P: n/a
Hi

I am attempting to write a small application that will allow users to
manage the AddressBar entries within Internet Explorer. The typed URLs
in the AddressBar can be found at
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs and I
have successfully managed to get this list via a Windows C# .NET app
with the following code :

public Form1()
{
InitializeComponent();
try
{
RegistryKey key = Registry.CurrentUser;
RegistryKey urlKey =
key.OpenSubKey(@"Software\Microsoft\InternetExplor er\TypedURLs");
keyNames = urlKey.GetValueNames();

foreach(string s in keyNames)
{
lbTypedUrls.Items.Add(urlKey.GetValue(s));
}
}
catch(Exception e)
{
MessageBox.Show(this, "Error Occurred : " + e.Message);
}
}

This works fine and my listbox is correctly populated with the
AdressBar URLs.

However, if I try the same technique in a Web App using the following
code :

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
try
{
RegistryKey key = Registry.CurrentUser;
RegistryKey urlKey =
key.OpenSubKey(@"Software\Microsoft\Internet Explorer\TypedURLs");
keyNames = urlKey.GetValueNames();

foreach(string s in keyNames)
{
lbTypedUrls.Items.Add(urlKey.GetValue(s).ToString( ));
}
}
catch(Exception exp)
{
Response.Write("An Error Occurred : " + exp.Message);
}
}
}

I am getting an error stating that, "An Error Occurred : Object
reference not set to an instance of an object."
The line : RegistryKey urlKey =
key.OpenSubKey(@"Software\Microsoft\Internet Explorer\TypedURLs"); Is
failing to load the RegistryKey object.

Can anyone see anything obvious that I am missing or have done wrong?
I don't think this is a permissions error. I have Web.config set up to
impersonate a specific username/password that definately has access to
the reg key.

I have read various other threads were people are receiving Permission
errors but I am not even getting that far :)

The app that I am writing will not be 'Served' over the internet but
will be installed as an App to run on a local machine. I just want to
use IE as the User Interface.

Any help would be greatly appreciated.

Many thanks,
Martin
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
web applications run under the doctrine of least priviledge (i love that
term). What it means is that you normally do not have permissions to access
the registry unless you explicitly turn that settting on. If you believe you
have turned that setting on then you can use the regmon utility to view the
registry key access.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
"Martin" <ma********@btinternet.com> wrote in message
news:34**************************@posting.google.c om...
Hi

I am attempting to write a small application that will allow users to
manage the AddressBar entries within Internet Explorer. The typed URLs
in the AddressBar can be found at
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs and I
have successfully managed to get this list via a Windows C# .NET app
with the following code :

public Form1()
{
InitializeComponent();
try
{
RegistryKey key = Registry.CurrentUser;
RegistryKey urlKey =
key.OpenSubKey(@"Software\Microsoft\InternetExplor er\TypedURLs");
keyNames = urlKey.GetValueNames();

foreach(string s in keyNames)
{
lbTypedUrls.Items.Add(urlKey.GetValue(s));
}
}
catch(Exception e)
{
MessageBox.Show(this, "Error Occurred : " + e.Message);
}
}

This works fine and my listbox is correctly populated with the
AdressBar URLs.

However, if I try the same technique in a Web App using the following
code :

private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
try
{
RegistryKey key = Registry.CurrentUser;
RegistryKey urlKey =
key.OpenSubKey(@"Software\Microsoft\Internet Explorer\TypedURLs");
keyNames = urlKey.GetValueNames();

foreach(string s in keyNames)
{
lbTypedUrls.Items.Add(urlKey.GetValue(s).ToString( ));
}
}
catch(Exception exp)
{
Response.Write("An Error Occurred : " + exp.Message);
}
}
}

I am getting an error stating that, "An Error Occurred : Object
reference not set to an instance of an object."
The line : RegistryKey urlKey =
key.OpenSubKey(@"Software\Microsoft\Internet Explorer\TypedURLs"); Is
failing to load the RegistryKey object.

Can anyone see anything obvious that I am missing or have done wrong?
I don't think this is a permissions error. I have Web.config set up to
impersonate a specific username/password that definately has access to
the reg key.

I have read various other threads were people are receiving Permission
errors but I am not even getting that far :)

The app that I am writing will not be 'Served' over the internet but
will be installed as an App to run on a local machine. I just want to
use IE as the User Interface.

Any help would be greatly appreciated.

Many thanks,
Martin

Nov 18 '05 #2

P: n/a
Hi Alvin

Thanks for your reply.

I have to admit that I am not familiar with 'Regmon'. I've just done a
search on my machine and nothing was found with this name.

Can you point me more specifically to the tool I should use.

Regards,
Martin

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message news:<#M**************@TK2MSFTNGP12.phx.gbl>...
web applications run under the doctrine of least priviledge (i love that
term). What it means is that you normally do not have permissions to access
the registry unless you explicitly turn that settting on. If you believe you
have turned that setting on then you can use the regmon utility to view the
registry key access.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...

Nov 18 '05 #3

P: n/a
sorry for not being clearer. start here
http://gethelp.devx.com/techtips/nt_.../10min0898.asp
it is a third party component but every bit of it is worth it

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/27cok
"Martin" <ma********@btinternet.com> wrote in message
news:34**************************@posting.google.c om...
Hi Alvin

Thanks for your reply.

I have to admit that I am not familiar with 'Regmon'. I've just done a
search on my machine and nothing was found with this name.

Can you point me more specifically to the tool I should use.

Regards,
Martin

"Alvin Bruney [MVP]" <vapor at steaming post office> wrote in message
news:<#M**************@TK2MSFTNGP12.phx.gbl>...
web applications run under the doctrine of least priviledge (i love that
term). What it means is that you normally do not have permissions to
access
the registry unless you explicitly turn that settting on. If you believe
you
have turned that setting on then you can use the regmon utility to view
the
registry key access.

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.