Requested registry access is not allowed.


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Requested registry access is not allowed.

  1. #1
    Robert Sherman Guest

    Requested registry access is not allowed.


    Server Error in '/5040' Application.
    --------------------------------------------------------------------------------

    Security Exception
    Description: The application attempted to perform an operation not allowed
    by the security policy. To grant this application the required permission
    please contact your system administrator or change the application's trust
    level in the configuration file.

    Exception Details: System.Security.SecurityException: Requested registry
    access is not allowed.

    Source Error:


    Line 18: Dim LogName As String = "MyApplicationLog"
    Line 19: Dim SourceName As String = "MyApplicationSource"
    Line 20: If (Not EventLog.SourceExists(SourceName))
    Line 21: EventLog.CreateEventSource(SourceName, LogName)
    Line 22: End If


    Source File: C:\BegASPNET\ch17\entrytolog.aspx Line: 20

    Stack Trace:


    [SecurityException: Requested registry access is not allowed.]
    Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
    +441
    System.Diagnostics.EventLog.FindSourceRegistration(String source, String
    machineName, Boolean readOnly) +295
    System.Diagnostics.EventLog.SourceExists(String source, String machineName)
    +78
    System.Diagnostics.EventLog.SourceExists(String source) +11
    ASP.entrytolog_aspx.Page_Error(Object sender, EventArgs exc) in C:\BegASPNET\ch17\entrytolog.aspx:20
    System.Web.UI.TemplateControl.OnError(EventArgs e) +109
    System.Web.UI.Page.HandleError(Exception e) +68
    System.Web.UI.Page.ProcessRequestMain() +2065
    System.Web.UI.Page.ProcessRequest() +118
    System.Web.UI.Page.ProcessRequest(HttpContext context) +18
    System.Web.CallHandlerExecutionStep.Execute() +179
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    +87




    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:1.0.3705.209; ASP.NET
    Version:1.0.3705.0


    How do you set Application trust level?
    What configuration file?

  2. #2
    Bill McCarthy Guest

    Re: Requested registry access is not allowed.

    Hi Robert,

    The reason you are getting this error is because the ASP.NET application does not
    have this permission. It will also probably not have the permission to create an
    event log too (line 21).

    You can change the permission set for ASP.NET, and/or use impersonation etc.
    However, a different approach you can take is to wrap up your event logging into a
    separate dll. This way you can programmatically set what you want to allow without
    opening up the registry to the ASP.NET app. Use a security assertion in your
    event logging dll. You will also need to configure that dll with the required
    level of trust (probably medium) which you can do in the ..NET Framework
    Configuration tool (under Administration tools). To do this just create a code
    group under the Runtime Security Policy\ Machine\Code Groups node, select your
    event log dll and set the level to the appropriate one. There is a wizard that
    will do this for you too if you like, but I don't like the default names it uses
    for code groups.

    So that would be the approach I would take. Rather than grant your web more
    access, wrap up the code that requires more permissions into a secure dll. This
    should keep your application as secure as possible while still allowing you to do
    things such as write to and create event logs.




    "Robert Sherman" <toyota2k@bellsouth.net> wrote in message
    news:3cc9518f$1@10.1.10.29...
    >
    > Server Error in '/5040' Application.
    > --------------------------------------------------------------------------------
    >
    > Security Exception
    > Description: The application attempted to perform an operation not allowed
    > by the security policy. To grant this application the required permission
    > please contact your system administrator or change the application's trust
    > level in the configuration file.
    >
    > Exception Details: System.Security.SecurityException: Requested registry
    > access is not allowed.
    >
    > Source Error:
    >
    >
    > Line 18: Dim LogName As String = "MyApplicationLog"
    > Line 19: Dim SourceName As String = "MyApplicationSource"
    > Line 20: If (Not EventLog.SourceExists(SourceName))
    > Line 21: EventLog.CreateEventSource(SourceName, LogName)
    > Line 22: End If
    >
    >
    > Source File: C:\BegASPNET\ch17\entrytolog.aspx Line: 20
    >
    > Stack Trace:
    >
    >
    > [SecurityException: Requested registry access is not allowed.]
    > Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
    > +441
    > System.Diagnostics.EventLog.FindSourceRegistration(String source, String
    > machineName, Boolean readOnly) +295
    > System.Diagnostics.EventLog.SourceExists(String source, String machineName)
    > +78
    > System.Diagnostics.EventLog.SourceExists(String source) +11
    > ASP.entrytolog_aspx.Page_Error(Object sender, EventArgs exc) in

    C:\BegASPNET\ch17\entrytolog.aspx:20
    > System.Web.UI.TemplateControl.OnError(EventArgs e) +109
    > System.Web.UI.Page.HandleError(Exception e) +68
    > System.Web.UI.Page.ProcessRequestMain() +2065
    > System.Web.UI.Page.ProcessRequest() +118
    > System.Web.UI.Page.ProcessRequest(HttpContext context) +18
    > System.Web.CallHandlerExecutionStep.Execute() +179
    > System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&

    completedSynchronously)
    > +87
    >
    >
    >
    >
    > --------------------------------------------------------------------------------
    > Version Information: Microsoft .NET Framework Version:1.0.3705.209; ASP.NET
    > Version:1.0.3705.0
    >
    >
    > How do you set Application trust level?
    > What configuration file?




  3. #3
    Robert Sherman Guest

    Re: Requested registry access is not allowed.


    >How do you set Application trust level????????
    >What configuration file?




    "Robert Sherman" <toyota2k@bellsouth.net> wrote:
    >
    >Server Error in '/5040' Application.
    >--------------------------------------------------------------------------------
    >
    >Security Exception
    >Description: The application attempted to perform an operation not allowed
    >by the security policy. To grant this application the required permission
    >please contact your system administrator or change the application's trust
    >level in the configuration file.
    >
    >Exception Details: System.Security.SecurityException: Requested registry
    >access is not allowed.
    >
    >Source Error:
    >
    >
    >Line 18: Dim LogName As String = "MyApplicationLog"
    >Line 19: Dim SourceName As String = "MyApplicationSource"
    >Line 20: If (Not EventLog.SourceExists(SourceName))
    >Line 21: EventLog.CreateEventSource(SourceName, LogName)
    >Line 22: End If
    >
    >
    >Source File: C:\BegASPNET\ch17\entrytolog.aspx Line: 20
    >
    >Stack Trace:
    >
    >
    >[SecurityException: Requested registry access is not allowed.]
    > Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
    >+441
    > System.Diagnostics.EventLog.FindSourceRegistration(String source, String
    >machineName, Boolean readOnly) +295
    > System.Diagnostics.EventLog.SourceExists(String source, String machineName)
    >+78
    > System.Diagnostics.EventLog.SourceExists(String source) +11
    > ASP.entrytolog_aspx.Page_Error(Object sender, EventArgs exc) in C:\BegASPNET\ch17\entrytolog.aspx:20
    > System.Web.UI.TemplateControl.OnError(EventArgs e) +109
    > System.Web.UI.Page.HandleError(Exception e) +68
    > System.Web.UI.Page.ProcessRequestMain() +2065
    > System.Web.UI.Page.ProcessRequest() +118
    > System.Web.UI.Page.ProcessRequest(HttpContext context) +18
    > System.Web.CallHandlerExecutionStep.Execute() +179
    > System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&

    completedSynchronously)
    >+87
    >
    >
    >
    >
    >--------------------------------------------------------------------------------
    >Version Information: Microsoft .NET Framework Version:1.0.3705.209; ASP.NET
    >Version:1.0.3705.0
    >
    >
    >How do you set Application trust level?
    >What configuration file?



  4. #4
    Bill McCarthy Guest

    Re: Requested registry access is not allowed.

    Hi Robert,

    Okay, since you have reposted your question here, I presume you weren't happy with
    the answer I provided. I believe the approach I suggested is the correct one to
    take, but if you want to take another approach that decision is yours. I do
    however recommend you read up on security before making any of these changes, as
    they can compromise security not only on your web server but the whole network or
    enterprise.

    So, anyway, looking at the code and stack trace you posted, it seems that you may
    be trying to run a sample from a book, Chapter 17, and at a guess, I presume the
    "Beg" part of the path indicates the book is something along the lines of
    Beginning .... ASP.NET

    If that is the case then you might only want to run the samples and may not be
    concerned about security issues. ( BTW: probably a good idea to contact the
    author.) If that is the case then you can :

    (i) just create the event log then the code should work. It is the creation of the
    event log that is causing the troubles.

    (ii) change the asp.net process model to one of higher trust. I would not
    recommend this, but that's up to you. To do this open the machine.config file in
    the Microsoft.Net/Config folder (probably located inside the Windows folder), then
    look for the processModel entry that is a child of the <system.web> node.
    Instructions are given in comments in the config file. You can set the account to
    SYSTEM, or to some other user name etc. Make sure you kill IIS and the
    aspnet_wp.exe process. Then restart IIS and the code should work.


    Note: if you are using impersonation, then you will need to check the accounts
    used, and (ii) above might not apply, depending on your other code. See your
    web.config file for settings.


    If you actually go to use this in production, please so not use (ii) above, rather
    either use (i) or the other approach as I outlined in my previous post. Setting
    the machine process for System.Web to a high level of trust account is a very
    dangerous thing to do, and should be avoided, especially when there are more
    secure and robust solutions.







    "Robert Sherman" <toyota2k@bellsouth.net> wrote in message
    news:3cc9c7f1$3@10.1.10.29...
    >
    > >How do you set Application trust level????????
    > >What configuration file?

    >
    >
    >
    > "Robert Sherman" <toyota2k@bellsouth.net> wrote:
    > >
    > >Server Error in '/5040' Application.

    >
    >--------------------------------------------------------------------------------
    > >
    > >Security Exception
    > >Description: The application attempted to perform an operation not allowed
    > >by the security policy. To grant this application the required permission
    > >please contact your system administrator or change the application's trust
    > >level in the configuration file.
    > >
    > >Exception Details: System.Security.SecurityException: Requested registry
    > >access is not allowed.
    > >
    > >Source Error:
    > >
    > >
    > >Line 18: Dim LogName As String = "MyApplicationLog"
    > >Line 19: Dim SourceName As String = "MyApplicationSource"
    > >Line 20: If (Not EventLog.SourceExists(SourceName))
    > >Line 21: EventLog.CreateEventSource(SourceName, LogName)
    > >Line 22: End If
    > >
    > >
    > >Source File: C:\BegASPNET\ch17\entrytolog.aspx Line: 20
    > >
    > >Stack Trace:
    > >
    > >
    > >[SecurityException: Requested registry access is not allowed.]
    > > Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
    > >+441
    > > System.Diagnostics.EventLog.FindSourceRegistration(String source, String
    > >machineName, Boolean readOnly) +295
    > > System.Diagnostics.EventLog.SourceExists(String source, String machineName)
    > >+78
    > > System.Diagnostics.EventLog.SourceExists(String source) +11
    > > ASP.entrytolog_aspx.Page_Error(Object sender, EventArgs exc) in

    C:\BegASPNET\ch17\entrytolog.aspx:20
    > > System.Web.UI.TemplateControl.OnError(EventArgs e) +109
    > > System.Web.UI.Page.HandleError(Exception e) +68
    > > System.Web.UI.Page.ProcessRequestMain() +2065
    > > System.Web.UI.Page.ProcessRequest() +118
    > > System.Web.UI.Page.ProcessRequest(HttpContext context) +18
    > > System.Web.CallHandlerExecutionStep.Execute() +179
    > > System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&

    > completedSynchronously)
    > >+87
    > >
    > >
    > >
    > >

    >
    >--------------------------------------------------------------------------------
    > >Version Information: Microsoft .NET Framework Version:1.0.3705.209; ASP.NET
    > >Version:1.0.3705.0
    > >
    > >
    > >How do you set Application trust level?
    > >What configuration file?

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center