All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
怎样在PHP,中运用,SimpleXML,处理任务_php资料_编程技术
菜鸟到高手:SQL开发进阶常用精妙语句_[SQL,Server教程]
如何在Asp.net中使用HtmlArea编辑器_[Asp.Net教程]
LINQ体验(14)——LINQ,to,SQL语句之存储过程_[Asp.Net教程]
PHP实现简单线性回归之数学库的重要性_[PHP教程]
ASP.NET,MVC,Framework体验(1):从一个简单实例开始_[Asp.Net教程]
C#的Windows编程中多语言的实现_.net资料_编程技术
全面接触SQL语法(5)_[SQL,Server教程]
Asp.net的身份验证_[Asp.Net教程]
独家:C#数据库操作的三种经典用法_.net资料_编程技术
Reading number is top 10 pictures
传几朵花
Group of female porn in 《westwards》, uninhibited woman threatened to not the bottom line2
清纯性感的美眉1
农夫山泉变身记
Summer is most suitable for young people to travel in China6
Summer is most suitable for young people to travel in China1
NeedWallpaper2
美女和狗狗2
传销的好处
关于海盗的研究
Download software ranking
I'm come from Beijing1
徐若瑄成名作“魔鬼天使”
Ashlynn Video1
Tram sex maniac 2 (H) rar bag3
中国结婚习俗实录
虚拟机汉化软件
Eclipse 4.2.1 For Win32
Unix video tutorial7
The cock of the Grosvenor LTD handsome
变速齿轮3.26
delv published in(发表于) 2014/1/10 6:31:44 Edit(编辑)
如何用在ASP.NET中写入事件日志_[Asp.Net教程]

如何用在ASP.NET中写入事件日志_[Asp.Net教程]

如何用在ASP.NET中写入事件日志_[Asp.Net教程]

文包含有关编辑注册表的信息。编辑注册表之前,务必先了解在发生问题时如何还原注册表。有关如何还原注册表的信息,请查看 Regedit.exe 中的“还原注册表”帮助主题,或 Regedt32.exe 中的“还原注册表项”帮助主题。
  现象


  当你使用asp.net 向事件日志中写入一个新的“事件来源”时,可能会得到如下错误消息: System.Security.SecurityException: 不允许所请求的注册表访问权


  原因


  运行asp.net进程的默认怅户是ASPNET(在IIS6.0下面是NetworkService),而此用户并没有权限来创建“事件来源”。


  解决办法


  注意:(编辑注册表会导致系统崩溃之类的微软吓你的话就不多说)。如果你需要解决此问题,在你运行此Asp.net程序之前,则必须要由具有管理员权限的用户来创建一个“事件来源”。下面有几个方法用来创建 “事件来源”。


  第一个方法


  使用下列步骤在注册表编辑中在”应用程序日志”下面创建一个“事件来源”


   1. 点击“开始”,再点击“运行”。


   2. 在“打开”框中输入“regedit”。


   3. 找到下列子键:


HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application


   4. 右击“Application”点击“新建”再点“项”


   5. 将此新建项重命名为“Test”


   6. 关闭注册表编辑器


  第二个方法


  在System.Diagnostics命名空间中有一个EventLogInstaller类。它能够创建和配置你的应用程序在运时要读写的事件日志。通过下列步骤,我们能够使用EventLogInstaller类来创建一个“事件业源”


  1. 用VB.NET或C#来创建一个名为EventLogSourceInstaller的“类库”。


  2. 在项目中添加对System.Configuration.Install.dll,的引用。


  3. 将自动产生的Class.Vb\Class.cs更命名为MyEventLogInstaller.vb\MyEventLogInstaller.cs。


  4. 在MyEventLogInstaller.vb 或 MyEventLogInstaller.cs中的内容替换为以下代码:


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..\computer\DownloadFiles\article\27\, 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..\computer\DownloadFiles\article\27\, 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);
}
}
}


  5. 生成此项目,得到EventLogSourceInstaller.dll。


  6. 打开Visual Studio .NET 命令提示,转到EventLogSourceInstaller.dll所在目录。


  7. 运行此命令来创建“事件来源”:InstallUtil EventLogSourceInstaller.dll


  更详尽的信息


  我们通过一个创建一个Web Application来重现以上错误以及解决此问题。


  1. 使用VB.Net或C#建立一个Asp.net Web Application。


  2. 在WebForm1.aspx中的代码替换为以下代码:


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..\computer\DownloadFiles\article\27\, e As EventArgs)
Dim ev As New EventLog("Application")
' Event's Source name
ev.Source = "TEST"


EventLog.CreateEventSource(ev.Source..\computer\DownloadFiles\article\27\, "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..\computer\DownloadFiles\article\27\, EventArgs e)
{
EventLog ev = new EventLog("Application");
// Event's Source name
ev.Source = "TEST";


EventLog.CreateEventSource(ev.Source..\computer\DownloadFiles\article\27\, "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. 按F5启动此项目。


  4. 在TextBox输入一些字符,然后点击Write to Event Log。


  5. 在上面“现象”部分中提到的错误消息会出现。


  6. 要解决此问题,在Webform1.aspx将下面这行代码注释



EventLog.CreateEventSource(ev.Source..\computer\DownloadFiles\article\27\, "Application");


  7. 重新启动此项目。


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.