关于ASP.Net写注册表权限问题的官方解决方法

asp.net|解决|问题|注册表

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

The information in this article applies to:

  • Microsoft ASP.NET (included with the .NET Framework) 1.0
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual C# .NET (2002)

This article was previously published under Q329291 IMPORTANT: This article contains information about modifying the registry. Before you modify the registry, make sure to back it up and make sure that you understand how to restore the registry if a problem occurs. For information about how to back up, restore, and edit the registry, click the following article number to view the article in the Microsoft Knowledge Base:
256986 Description of the Microsoft Windows RegistrySYMPTOMSWhen you create a new event source in the event log by using ASP.NET, you may receive the following error message:
System.Security.SecurityException: Requested registry access is not allowed.CAUSEBy default, the user token of the ASP.NET worker process is ASPNET. The problem in the "Symptoms" section occurs because your account does not have the correct user rights to create an event source. RESOLUTIONWARNING: If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk. To resolve this problem, a user who has administrative rights must create the event source before you run the ASP.NET Web Application. To create an event source, use one of the following approaches.

First Approach

Create an event source under the Application event log in Registry Editor. To do this, follow these steps:

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

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Use Visual Basic .NET or Visual C# .NET to create a new ASP.NET Web Application. By default, WebForm1.aspx file is created.
  2. In the HTML view of WebForm1.aspx, replace the existing code with the following sample code:

    Visual Basic .NET Sample

    <%@ 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>

    Visual C# .NET Sample

    <%@ 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>
  3. On the Debug menu, click Start to view the WebForm1.aspx page in the browser.
  4. Type some text in TextBox, and then click Write to event log.
  5. The error message that is discussed in the "Symptoms" section of this article appears.
  6. To resolve this problem, create an Event Source as discussed in the "Resolution" section, and comment the following code in WebForm1.aspx :
    EventLog.CreateEventSource(ev.Source, "Application")
  7. Repeat steps 3 and 4.

REFERENCESFor more information, visit the following Microsoft Web sites:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkWalkthroughCreatingEventLogInstallers.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdiagnosticseventlogclasstopic.aspLast Reviewed:1/3/2003Keywords:kbprb kberrmsg kbWebForms kbSecurity KB329291 kbAudDeveloper kbAudITPRO

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索net
, application
, visual
, source
, microsoft
, ackage nstaller
The
,以便于您获取更多的相关知识。

时间: 2024-11-08 06:41:15

关于ASP.Net写注册表权限问题的官方解决方法的相关文章

ASP不能打开注册表关键字错误 &#039;80004005&#039;的解决方法_应用技巧

如果出现如下错误: Microsoft OLE DB Provider for ODBC Drivers 错误 '80004005' [Microsoft][ODBC Microsoft Access Driver]常见错误 不能打开注册表关键字 'Temporary (volatile) Jet DSN for process 0xa78 Thread 0xadc DBC 0x26a0cfc Jet'. 第一步:请设置数据库文件为可以让用户IUSR_Machine(匿名访问使用帐户)有可写权限

ASP不能打开注册表关键字错误 '80004005'的解决方法

如果出现如下错误: Microsoft OLE DB Provider for ODBC Drivers 错误 '80004005' [Microsoft][ODBC Microsoft Access Driver]常见错误 不能打开注册表关键字 'Temporary (volatile) Jet DSN for process 0xa78 Thread 0xadc DBC 0x26a0cfc Jet'. 第一步:请设置数据库文件为可以让用户IUSR_Machine(匿名访问使用帐户)有可写权限

无法显示隐藏文件夹(修改过注册表也无效)的解决方法 附注册表文件_注册表

显示隐藏文件的通法: 正常情况下,按照如下顺序操作即可:打开"我的电脑"的"工具"菜单--"文件夹选项",在"查看"标签里,选择"显示所有文件和文件夹",并找到"隐藏受保护的操作系统文件(推荐)",将前面的勾去掉.如下图所示: 被病毒修改注册表后导致无法显示隐藏文件的解决方法: 如果是由于病毒所导致的,则有很多种情况,这里说一下较常用的两种方法. 法一:打开注册表编辑器,进入注册表项:H

注册表编辑器被禁用的解决方法

 1.开始菜单_运行--输入regedit--确定. 2.开始---运行---输入Gpedit.msc --回车--用户配置--管理模版--系统--双击右侧窗口中的"阻止访问注册表编辑工具",在弹出的窗口中选择"已禁用"-确定. 3.使用工具软件 如优化大师.超级兔子等,都有个注册表锁定与解锁的设置,对于已经安装了这些软件的用户,这的方法是比较方便的. 打开超级兔子,进入"超级兔子魔法设置"--"系统"--去掉"禁止

mfc-我用VC在HKEY_LOCAL_MACHINE下写注册表不成功,而在其他如HKEY_CURRENT_USER却行

问题描述 我用VC在HKEY_LOCAL_MACHINE下写注册表不成功,而在其他如HKEY_CURRENT_USER却行 我用的是win8.1系统,我提升了进程权限也没有反应,不知道是不是方法不对 解决方案 GetLastError 看看返回值,

regini dos下更改注册表权限的工具_DOS/BAT

这个玩意主要用途是 在cmd下 修改注册表 以及 注册表权限! 用法研究了一晚上 弄出来了 ,微软上写的 根本不能用啊 郁闷.. 使用方法 C:\>regini regset.ini 就行啦 regset.ini 是你要修改的数据 下面举例! regset.ini 文件内容 引用: 复制代码 代码如下: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run test = c:\windows\system32\fuckt

VS2010中MFC写注册表RegCreateKey

问题描述 VS2010中MFC写注册表RegCreateKey HKEY hKey ; RegCreateKey(HKEY_LOCAL_MACHINE , TEXT("Software\MyRegisterTest\admin") , &hKey) ; RegSetValue(hKey , NULL , REG_SZ , TEXT("zhangsan") , strlen("zhangsan")) ; //RegCreateKey(HKE

修改注册表权限加强对木马、病毒的防范_注册表

  一.问题的提出 大部分的木马及部分的病毒是通过注册表的自启动项或文件关联或通过系统服务实现自启动的,详见<Windows的自启动方式>,那是否有一种方法可以防止木马或病毒修改注册表项及增加服务呢? 二.问题的解决 windows2000/xp/2003的注册表是可以设置权限的,只是我们比较少用到.设置以下注册表键的权限: 1.设置注册表自启动项为everyone只读(Run.RunOnce.RunService),防止木马.病毒通过自启动项目启动 2.设置.txt..com..exe..i

ie11-通过写注册表文件将某个网站加入到兼容性视图中

问题描述 通过写注册表文件将某个网站加入到兼容性视图中 例如:添加信任站点可以这样设置:(IP) [HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionInternet SettingsZoneMapRangesRange113240226136] "http"=dword:00000002 ":Range"="113.240.226.136",通过想用同样的办法将该网站加入到兼容性视图网