这个问题出现于在存储过程查询过程中出错,写日志时产生,报错信息如:
安全性异常
说明: 应用程序试图执行安全策略不允许的操作。要授予此应用程序所需的权限,请与系统管理员联系,或在配置文件中更改该应用程序的信任级别。
异常详细信息: System.Security.SecurityException: 不允许所请求的注册表访问权。
源错误:
Exception lastError = Server.GetLastError(); string errMsg = lastError.ToString(); string message = "Url " + Request.Path + " Error: " + errMsg; string logname = "报表系统"; if (!EventLog.SourceExists(logname)) { // EventLog.CreateEventSource(logname, logname); } EventLog alog = new EventLog(); alog.Source = logname; alog.MaximumKilobytes = 10240; //lastError.GetType alog.WriteEntry(message, EventLogEntryType.Information, 1);
解决方法:
运行 regedt32 程序
进入 HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Eventlog 目录
点击 安全=>权限 菜单进行设置
赋予 ASPNET(Win2K/XP) 或 Network Service(Win2003) 完全控制权限
通过regedt32(windows2000系统,在菜单“安全”下的“权限”)或regedit(windows2003/xp,在“编辑”菜单下的“权限”)