Problems accessing registry keys within ASP.NET application

Discussion in 'ASP .Net' started by Martin, Apr 18, 2004.

  1. Martin

    Martin Guest

    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\InternetExplorer\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
     
    Martin, Apr 18, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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\InternetExplorer\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
     
    Alvin Bruney [MVP], Apr 18, 2004
    #2
    1. Advertising

  3. Martin

    Martin Guest

    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:<#>...
    > 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...
     
    Martin, Apr 19, 2004
    #3
  4. sorry for not being clearer. start here
    http://gethelp.devx.com/techtips/nt_pro/10_minute_solutions/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" <> wrote in message
    news:...
    > 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:<#>...
    >> 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...
     
    Alvin Bruney [MVP], Apr 19, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gxdata

    Registry keys for .NET 1.0

    gxdata, May 28, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,226
    gxdata
    Jun 2, 2005
  2. Christina Androne

    ASP.NET registry keys

    Christina Androne, Jan 2, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    6,251
    Andy Mortimer [MS]
    Jan 5, 2004
  3. HK
    Replies:
    1
    Views:
    3,668
    Cowboy \(Gregory A. Beamer\)
    Apr 1, 2004
  4. Isaias Formacio Serna

    Problem accessing Windows 2003 DC Registry Keys

    Isaias Formacio Serna, Dec 11, 2003, in forum: ASP .Net Security
    Replies:
    0
    Views:
    119
    Isaias Formacio Serna
    Dec 11, 2003
  5. rhenders
    Replies:
    1
    Views:
    178
    rhenders
    Oct 7, 2005
Loading...

Share This Page