When you use ASP.NET to create a new event source in the event log, you may receive the following error message:
System.Security.SecurityException: Requested registry access is not allowed.
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.
Imports System.Diagnostics
Imports System.Configuration.Install
Imports System.ComponentModel
<RunInstaller(True)> _
Public Class MyEventLogInstaller
Inherits Installer
Private myEventLogInstaller As EventLogInstaller
Public Sub New()
' Create an instance of 'EventLogInstaller'.
myEventLogInstaller = New EventLogInstaller()
' Set the 'Source' of the event log, to be created.
myEventLogInstaller.Source = "TEST"
' Set the 'Log' that the source is created in.
myEventLogInstaller.Log = "Application"
' Add myEventLogInstaller to 'InstallerCollection'.
Installers.Add(myEventLogInstaller)
End Sub
End Class
using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Configuration.Install;
namespace EventLogSourceInstaller
{
[RunInstaller(true)]
public class MyEventLogInstaller : Installer
{
private EventLogInstaller myEventLogInstaller;
public MyEventLogInstaller()
{
//Create Instance of EventLogInstaller
myEventLogInstaller = new EventLogInstaller();
// Set the Source of Event Log, to be created.
myEventLogInstaller.Source = "TEST";
// Set the Log that source is created in
myEventLogInstaller.Log = "Application";
// Add myEventLogInstaller to the Installers Collection.
Installers.Add(myEventLogInstaller);
}
}
}
<%@ Page Language="vb" AutoEventWireup="true" %>
<%@ Import namespace="System.Diagnostics" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<script language="VB" runat="server">
Sub WriteEvent_Click(Src As Object, e As EventArgs)
Dim ev As New EventLog("Application")
' Event's Source name
ev.Source = "TEST"
EventLog.CreateEventSource(ev.Source, "Application")
Try
ev.WriteEntry(TextBox1.Text)
Catch b as exception
Response.write ("WriteEntry " & b.message & "<br>")
End Try
ev = Nothing
End Sub
</script>
<body>
<form id="Form1" runat="server">
Event message:
<asp:textbox id="TextBox1" runat="server" Width="233px"></asp:textbox>
<asp:button id="Button1" onclick="WriteEvent_Click" runat="server" NAME="Button1" text="Write to event log"></asp:button>
</form>
</body>
</HTML>
<%@ Page Language="c#" AutoEventWireup="true" %>
<%@ Import namespace="System.Diagnostics" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<script language="C#" runat="server">
void WriteEvent_Click(Object Src, EventArgs e)
{
EventLog ev = new EventLog("Application");
// Event's Source name
ev.Source = "TEST";
EventLog.CreateEventSource(ev.Source, "Application");
try
{
ev.WriteEntry(TextBox1.Text);
}
catch (Exception b)
{
Response.Write("WriteEntry " + b.Message + "<br>");
}
ev = null;
}
</script>
<body>
<form id="Form1" runat="server">
Event message:
<asp:textbox id="TextBox1" runat="server" Width="233px"></asp:textbox>
<asp:button id="Button1" onclick="WriteEvent_Click" runat="server" NAME="Button1" text="Write to event log"></asp:button>
</form>
</body>
</HTML>
EventLog.CreateEventSource(ev.Source, "Application")
Keywords: kbvs2003swept, kbaspwpswept, kberrmsg, kbwebforms, kbsecurity, kbprb, kb