动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP.NET技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ ASP.NET技巧 ]的信息

本月文章推荐
.关于2.0 中的用户控件编程使用.
.ASP.NET2.0中的AccessDataSource.
.ASP.NET设计网络硬盘之文件夹实现.
..net开发投票机的思路.
.RSS 文档中 language 标签中的可.
.asp.net错误处理封装.
.ASP.NET2.0下含有DropDownList的.
.解决网爬工具爬取页面信息出现乱.
.asp.net如何连接sql server2000数.
.page事件顺序(.net2.0) .
.ASP.NET 2.0 - Enter Key - Defa.
.配置.net 3.0开发环境.
.在asp.net中实现删除DataGrid的某.
.页面中包括DataGrid时,利用webc.
.Asp.net(c#)实现多线程断点续传.
.图片地址防盗链,通过IHttpHandle.
.ASP.NET入门随想之博德之门 类与.
.ASP.NET 2.0服务器控件开发精要.
.asp.net menu "Operation aborte.
.ASP.NET 中执行 URL 重写.

如何用在ASP.NET中写入事件日志

发表日期:2006-8-14 |


文包含有关编辑注册表的信息。编辑注册表之前,务必先了解在发生问题时如何还原注册表。有关如何还原注册表的信息,请查看 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. 重新启动此项目。

http://www.cnblogs.com/niit007/archive/2006/08/13/475510.html

上一篇:ASP.NET实现下载功能的中文文件名乱码处理 人气:7554
下一篇:ASP.net 验证码(C#) 人气:8802
浏览全部ASP.NET的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-10-13 爬爬思特新闻管理系统 v2.0 Beta1
2008-10-13 Pligg v9.9.5 Beta
2008-10-13 广优邮件发送系统 v2.1
2008-10-13 缤纷互动视频交友 v3.1 RC
2008-10-13 MyShop网络商城 build 081005
2008-10-13 Chyrp 超轻量级开源博客引擎 v2.
2008-10-13 162100静态(论坛/文章)系统 v2.4
2008-10-13 金博人才招聘求职网黄金版 v4.2
2008-10-13 愚人笔记 v4.0
2008-10-11 联系人分组工具 v1.1 中文破解版
2008-10-11 FaceMelter变脸 v2.0 汉化破解版
2008-10-11 PathTracker道路跟踪仪 v1.2 破解
2008-10-11 Rooms手机聊天室 v0.6.7 破解版
2008-10-11 RemoteDesktop远程桌面 v1.0 破解
2008-10-11 ProRemote远程调音台 v1.0.1 破解
2008-10-11 PicShare照片共享 v1.0.0 破解版
2008-10-11 Photogene照片编辑器 v1.5 汉化破
2008-10-11 WriteRoom共享文档 v1.0 破解版
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | 广告代码 | js/vbs加密 | md5加密 | 进制转换 | UTF-8 转换工具 | Html转换js | Html转换asp | Html转换php | Html转换perl
实用工具:汉字翻译拼音 | 拼音字典 | 符号对照表 | 个税计算 | 实时汇率查询换算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 | 国家代码与域名缩写 | 文字加密解密 | 健康查询 | 万年历 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報
防水工事·改修工事 フットサル大会 探偵
SEO対策 中国語教室 ホームページ作成