始终可用于写入的事件日志源?

发布于 2024-08-15 02:02:28 字数 273 浏览 8 评论 0 原文

是否存在始终可供 ASP.NET Web 应用程序写入的事件日志源?

背景故事,以防有人有看似不相关的解决方案:

我们的 ASP.NET Web 应用程序使用自己的事件日志源,但它无权创建它。因此,如果当 web 应用程序尝试写入条目时事件日志源不存在(安装说明指示管理员手动注册事件日志源,但是......),我们的 web 应用程序不会将任何内容放入出现问题时的事件日志。

我希望有另一个(与应用程序无关的)来源可以用来通知观看事件日志的人们。

Is there an event log source that's always available for writing by an ASP.NET webapp?

Backstory, in case anyone has a seemingly unrelated solution:

Our ASP.NET webapp uses its own event log source, but it doesn't have the rights to create it. So, if the event log source doesn't exist when the webapp tries to write the entry (install instructions dictate that the admin register the event log source manually, but......) , our webapp doesn't put anything in the event log when it has problems.

I'm hoping there's another (app-agnostic) source I can use to notify the folks who watch the event log.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

╰沐子 2024-08-22 02:02:28

这篇知识库文章解释了这个问题
http://support.microsoft.com/ KB/329291

PRB:当 ASP.NET 应用程序尝试在事件日志中写入新的 EventSource 时出现“不允许请求的注册表访问”错误消息

症状

当您使用 ASP.NET 在事件日志中创建新事件源时,您可能会收到以下错误消息:

<块引用>

System.Security.SecurityException:不允许请求的注册表访问。

原因

默认情况下,ASP.NET 工作进程的用户令牌是 ASPNET(对于在 Internet 信息服务 [IIS] 6.0 上运行的应用程序,则为 NetworkService)。出现“症状”部分中的问题是因为您的帐户没有创建事件源的正确用户权限。

分辨率

第一种方法:

在注册表编辑器中的应用程序事件日志下创建事件源(在服务器上,而不是您的开发 PC 上)。为此,请按照下列步骤操作:

  1. 访问服务器的 Windows 桌面。单击“开始”,然后单击“运行”。
  2. 在“打开”文本框中,键入 regedit。
  3. 找到以下注册表子项:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application
  4. 右键单击“应用程序”子项,指向新建,然后单击
  5. 键入“TEST”作为密钥名称。
  6. 关闭注册表编辑器。

第二种(替代)方法:

System.Diagnostics 命名空间中的 EventLogInstaller 类允许您安装和配置应用程序在运行时读取或写入的事件日志。您可以使用EventLogInstaller 创建事件源。为此,请按照下列步骤操作:

  1. 使用 Microsoft Visual Basic .NET 或 Microsoft Visual C# .NET 创建一个名为 EventLogSourceInstaller 的新类库。默认情况下,会创建 Class1.vb 文件或 Class1.cs 文件。
  2. 在解决方案资源管理器中,右键单击 EventLogSourceInstaller,然后单击“添加引用”。
  3. 在“添加引用”对话框中,双击“System.Configuration.Install.dll”,然后单击“确定”。
  4. Class1.vb`Class1.cs` 重命名为 MyEventLogInstaller.vb\MyEventLogInstaller.cs。
  5. MyEventLogInstaller.vbMyEventLogInstaller.cs 中的现有代码替换为以下示例代码:
    Visual Basic .NET 示例
导入系统.诊断
导入系统.配置.安装
导入 System.ComponentModel

<运行安装程序(真)> _
公共类 MyEventLogInstaller
    继承安装程序
    将 myEventLogInstaller 私有为 EventLogInstaller

    公共子新建()
        ' 创建“EventLogInstaller”的实例。
        myEventLogInstaller = 新EventLogInstaller()
        ' 设置要创建的事件日志的“来源”。
        myEventLogInstaller.Source =“测试”
        ' 设置在其中创建源的“日志”。
        myEventLogInstaller.Log =“应用程序”
        ' 将 myEventLogInstaller 添加到 'InstallerCollection'。
        安装程序.添加(myEventLogInstaller)
    结束子 
结束课程 

Visual C# .NET 示例

使用系统;
使用系统诊断;
使用 System.ComponentModel;
使用系统.配置.安装;


命名空间EventLogSourceInstaller 
{
  [运行安装程序(真)]
  公共类 MyEventLogInstaller :安装程序
  {
      私有EventLogInstaller myEventLogInstaller;

      公共 MyEventLogInstaller()
      {
          //创建EventLogInstaller实例
          myEventLogInstaller = new EventLogInstaller();

          // 设置要创建的事件日志的来源。
          myEventLogInstaller.Source = "测试";

          // 设置创建源的日志
          myEventLogInstaller.Log = "应用程序";
          
          // 将 myEventLogInstaller 添加到安装程序集合中。
          Installers.Add(myEventLogInstaller);
      }
  }
}
  • 在“生成”菜单上,单击“生成解决方案”以创建 EventLogSourceInstaller.dll。
  • 打开 Visual Studio .NET 命令提示符。
  • 在命令提示符下,切换到 EventLogSourceInstaller.dll 所在的文件夹。
  • 运行以下命令创建 EventSource:InstallUtil EventLogSourceInstaller.dll
  • 如果您使用解决方案中的第二种方法,您应该可以使其正常工作。

    如果您不想这样做或者无法让它正常工作,另一种方法是使用 web.config 中的身份标签并模拟具有编辑权限的用户注册表。这只是此应用程序的安全整体,但如果您实施一些额外的安全措施,应该没问题。

    In this KB article it explains the issue
    http://support.microsoft.com/kb/329291

    PRB: "Requested Registry Access Is Not Allowed" Error Message When ASP.NET Application Tries to Write New EventSource in the EventLog

    Symptoms

    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.

    Cause

    By default, the user token of the ASP.NET worker process is ASPNET (or NetworkService for applications that run on Internet Information Services [IIS] 6.0). The problem in the "Symptoms" section occurs because your account does not have the correct user rights to create an event source.

    Resolution

    First approach:

    Create an event source under the Application event log in Registry Editor (on the server, not your development PC). To do this, follow these steps:

    1. Access the server's Windows desktop. Click Start, and then click Run.
    2. In the Open text box, type regedit.
    3. Locate the following registry subkey: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application
    4. Right-click the Application subkey, point to New, and then click Key.
    5. Type "TEST" for the key name.
    6. Close Registry Editor.

    Second (alternative) approach:

    The EventLogInstaller class in the System.Diagnostics namespace permits you to install and configure an event log that your application reads from or writes to while running. You can create an event source by using EventLogInstaller. To do this, follow these steps:

    1. Use Microsoft Visual Basic .NET or Microsoft Visual C# .NET to create a new Class Library named EventLogSourceInstaller. By default, the Class1.vb file or the Class1.cs file is created.
    2. In Solution Explorer, right-click EventLogSourceInstaller, and then click Add References.
    3. In the Add Reference dialog box, double-click System.Configuration.Install.dll, and then click OK.
    4. Rename the Class1.vb`Class1.cs` to MyEventLogInstaller.vb\MyEventLogInstaller.cs.
    5. Replace the existing code in MyEventLogInstaller.vb or MyEventLogInstaller.cs with the following sample code:
      Visual Basic .NET sample
    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 
    

    Visual C# .NET sample

    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);
          }
      }
    }
    
    1. On the Build menu, click Build Solution to create EventLogSourceInstaller.dll.
    2. Open the Visual Studio .NET Command Prompt.
    3. At the command prompt, change to the folder where EventLogSourceInstaller.dll is located.
    4. Run the following command to create the EventSource: InstallUtil EventLogSourceInstaller.dll

    If you use the second approach under the resolution you should get it to work.

    If you don't want to do that or you can't get it to work correctly another way would be to use the identity tag in your web.config and impersonate a user that does have rights to edit the registry. This is a security whole only for this application but if you implement some extra security measures you should be fine.

    泛滥成性 2024-08-22 02:02:28

    考虑过电子邮件通知吗?我猜有些管理员更喜欢通过手机收到通知。

    如果客户端拒绝在 HKLM\System\CurrentControlSet\Services\EventLog\ 下创建密钥,您也可以打电话回家(调用 Web 服务将日志写回您自己的服务器)

    Considered email notification? I guess some admins prefer to be notified from their cellphones.

    You could also ring home (call a web service to write log back to your own server), in case the client refuse to create a key under HKLM\System\CurrentControlSet\Services\EventLog\

    阳光下慵懒的猫 2024-08-22 02:02:28

    您可能无权从 Web 应用程序创建事件源,但如果没记错的话,您可以检查是否存在事件源。

    在 global.asax 或自定义处理程序中,检查他们是否按照预期创建了它。如果他们没有,在每个页面上都会显示一个非常烦人的提醒 div。一旦他们按照预期创建了它,div 就会消失:)

    You might not have access to create an event source from the web app, but if memory serves, you can check to see if one exists.

    In the global.asax or a custom handler, check to see if they created it like they were supposed to. If they didn't, have a really annoying reminder div show on every page. As soon as they create it like they were supposed to, the div goes away :)

    遥远的绿洲 2024-08-22 02:02:28

    “ASP.NET XYZ0 “我认为,源代码将始终可供编写。

    The "ASP.NET X.Y.Z.0" source will, I think, always be available for writing.

    提笔书几行 2024-08-22 02:02:28

    您应该能够毫无困难地写入内置事件日志(应用程序、安全性、系统)。

    You should be able to write to the built-in event logs (Application, Security, System) without much difficulty.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文