Re: Security- access to Event Viewer- SOS

From: Steven Cheng[MSFT] (v-schang_at_online.microsoft.com)
Date: 04/28/04


Date: Wed, 28 Apr 2004 03:37:43 GMT

Hi Patrick,

Thanks for your effort and time!

I would like to restate the current status as following. Please check if I
understood the problem correctly.

1. Now you are directly calling "WriteEntry" to add the event to the Event
Log. However, the error message still appear.

2. When you use impersonation on the Windows 2000 SP4 machine, the
test.aspx page works fine. However, without impersonation, it will fail.

If I have misunderstood, please don't hesitate to let me know.

Patrick, as we have discussed, if we do not enable impersonation, the
default account (ASPNET on Windows 2000) for ASP.NET work process do not
have permission to create the new event log category. This is the cause for
the error message.

However, by default the account "ASPNET" has permission to add one event
item with "WriteEntry". The following code also works fine on my side. Can
you help to double confirm with the following code on your side again?
Thanks for your help!

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Diagnostics;

namespace eventtest
{
        /// <summary>
        /// Summary description for WebForm1.
        /// </summary>
        public class WebForm1 : System.Web.UI.Page
        {
                protected System.Web.UI.WebControls.Button Button1;
        
                private void Page_Load(object sender, System.EventArgs e)
                {
                        // Put user code to initialize the page here
                }

                #region Web Form Designer generated code
                override protected void OnInit(EventArgs e)
                {
                        //
                        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                        //
                        InitializeComponent();
                        base.OnInit(e);
                }
                
                /// <summary>
                /// Required method for Designer support - do not modify
                /// the contents of this method with the code editor.
                /// </summary>
                private void InitializeComponent()
                {
                        this.Button1.Click += new System.EventHandler(this.Button1_Click);
                        this.Load += new System.EventHandler(this.Page_Load);

                }
                #endregion

                private void Button1_Click(object sender, System.EventArgs e)
                {
                        Logging.LogError("an error message");
                
                }
        }

        public class Logging
        {
                private const string EVENT_SOURCE = "YJBWEBSITE";
                private const string EVENT_LOG = "Applicaiton";

                public Logging()
                {
                        //Default constructor
                }

                public static void LogEventViewer(string
                        strMessage,EventLogEntryType objLogEntryType)
                {
                        try
                        {
                                EventLog objEventLog;

                                objEventLog = new EventLog();
                                objEventLog.Source = "application";

                                objEventLog.WriteEntry(strMessage,objLogEntryType);

                        }
                        catch (Exception e)
                        {

                                System.Console.WriteLine(e);
                                return;
                        } //end try

                } //end LogEventViewer

                public static void LogError(string strMessage)
                {
                        LogEventViewer(strMessage,EventLogEntryType.Error);
                }

        } //end class Logging
}

If there are any new findings, please feel free to let me know. Thanks!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


Loading