Results 1 to 4 of 4

Thread: Security Problem in EventLog.WriteEntry

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    india
    Posts
    273

    Security Problem in EventLog.WriteEntry

    hi buddies..
    i am facing very small problem . could you guys please tell ne the solution ..


    I have written the following code for event Logging. i am getting follwing error , i am not getting what settings to be changed to allow logging.

    EventLog.WriteEntry("Registration module","Two dataset generated!!",EventLogEntryType.Error,this.ID);

    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.

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: Security Problem in EventLog.WriteEntry

    Welcome to the fun, fun world of code access security... Your application is probably not running on your local machine, and thus the framework denies access to the registry and event logs (amongst other things).

    I'm going to walk you through creating your own code group, assigning your application to it and specifying permissions.
    You'll have to strongly name your assembly for this to work based on this example, however you may use the assembly URL - follows much of the same procedure.

    Open up Start > Control Panel > Administrative Tools > ".NET Configuration 1.1".
    Expand "Runtime Security Policy", "Machine" and "Code Groups".


    Right click on "All_Code" and select "New".
    Enter a name for your code group, e.g. "MyApplication" and click "Next".


    In the dropdown list, select "Strong Name".
    Click the "Import" button, browse to and select your application, and click "Next".


    For the purposes of this example, we'll use "Full Trust", however one may create a new permission set with the minimum requirements for your application (e.g. SQL client & event log access, etc)
    Select "Full Trust" from the dropdown list, and click "Next", then click "Finish".


    And to verify, open up the Visual Studio Command prompt, and navigate to your binary location (e.g. C:\My Projects\EventLogAccess_CAS\bin\debug\EventLogAccess_CAS.exe). Type in the following and hit <Enter>:
    caspol -rsg EventLogAccess_CAS.exe

    The screenshot "caspol_Verify.png" shows the output based on my configuration.


    I'll include the zipped C# project in the next post.
    Attached Images Attached Images      
    Last edited by axion_sa; Jan 28th, 2006 at 01:27 PM.

  3. #3
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724

    Re: Security Problem in EventLog.WriteEntry

    And the sample project goes here...
    Attached Files Attached Files

  4. #4
    Member
    Join Date
    Jan 2006
    Location
    UK
    Posts
    61

    Re: Security Problem in EventLog.WriteEntry

    Hi

    Another cause of what you are experiencing imay be that you may be running a web application under partial trust (ie. the trust level in web.config is not set to "Full").

    This is good, as it's best to not run your web apps under full trust. However, the event log and registry access will not run unless you create an intermediate 'Sandbox' assembly, asserting full trust.

    Here is a link that describes how to create a Sandbox assembly:

    http://msdn.microsoft.com/security/d...l/THCMCh09.asp

    Also, instructions for configuring security policies are contained in a white paper entitled:

    Security Solutions Offered by Visual Studio .Net 2005 (Whidbey)

    at

    http://www.charteris.com/publication...rs/default.asp


    Hope this helps

    Chris Seary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width