473,473 Members | 2,100 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need help on the Permissions needed to log to Event Log from ASP.NET?

Hello all.

I have a couple of aspx pages. When something fails in them, I would like
them to be able to log to either a database, a logfile, or the application
log. All code is in C#

I run into permissions problems straigh away though. To log to the event
log, you need Administrator privileges. So followed MS example how to
sandbox sensitive and secure code.
1) Made a new component, to sandbox the event log code, and to decrease the
possible attack surface.
2) Created a strong key, and added it to the assembly file.
3) Added the APTCA attribute ([assembly: AllowPartiallyTrustedCallers]),
and as per MS instructions, the following attribute also:
[assembly: EventLogPermission(SecurityAction.RequestMinimum,
PermissionAccess = EventLogPermissionAccess.Instrument)]
4) Added the component to the GAC
5) The code in the function looks like this:

public static bool LogEvent(string LogName, string Source, string User,
string LogText, int EventID, short Category)
{
EventLog oLog;
EventLogEntryType lEntry = EventLogEntryType.Error;
EventLogPermission oPerm;

string sMachine = System.Net.Dns.GetHostName();
string sLog;
bool bOK = false;
sLog = LogName;

Category = 0;
try
{
System.Text.StringBuilder oBuilder = new
System.Text.StringBuilder(LogText.Length + 100);

oBuilder.Append("Date: ");
oBuilder.Append (System.DateTime.Now.ToString());
oBuilder.Append("\n"); // new line

oBuilder.Append("User: ");
oBuilder.Append(User);
oBuilder.Append("\n\n"); // new line

oBuilder.Append(LogText);
// to allow untrusted callers the right to add entries to the event log.
oPerm = new EventLogPermission(EventLogPermissionAccess.Instru ment,
sMachine);
oPerm.Assert();

if (!EventLog.SourceExists(Source))
EventLog.CreateEventSource(Source, sLog, sMachine);

// using means that we don't have to explicitly call dispose at the end.
// Dispose is called implicitly at the end of the using bracket.
// Only supported for objects that implement IDisposable.
using (oLog = new EventLog(sLog, sMachine, Source))
{

string sEventDescription = oBuilder.ToString();

oLog.BeginInit();
oLog.WriteEntry(sEventDescription, lEntry, EventID, Category);
oLog.EndInit();
}
bOK = true;
}
catch (System.Security.SecurityException secEx)
{
bOK = false;
throw(secEx);
}
catch (System.Exception ex)
{
bOK = false;
throw(ex);
}
finally
{
CodeAccessPermission.RevertAll();

}

return bOK;
}
When this component is called from my aspx pages the following error occurs:

Description: The application attempted to perform an operation not allowed
by the security policy. To grant this application the required permission
please contact your system administrator or change the application's trust
level in the configuration file.

Exception Details: System.Security.SecurityException: Requested registry
access is not allowed.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
I have tried to modify the trust level in the web.config file, but to no
avail. Full trust level works no better than the default trust level.
Clearly, the pages do not have permissions to access the component, and to
execute the code.
I know that the code fails at the call to oLog.WriteEntry

Any idea how to do fix this? Need I configure some assemblies or some such?
Should I remove the demand for Instrument privelege for EventLogPermission?
Have tried to look at code groups under machine config in the .Neet
configuration tool, but nothing helps.

The web pages are running in the default ASP.NET account, as they are on a
public server, and running the web pages under an administrative account is
out of the question.

// Sincerily yours, Henrik
Nov 17 '05 #1
0 1286

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: MSDN Account | last post by:
We have web site that used the IIS ResKit tool MSWC.PermissionChecker to check file permissions. The web site has been upgraded and that upgrade included changing the default server side language...
4
by: Richard | last post by:
Hi all, Is there any class in .NET 1.x that will help me set file & folder permissions for a user? Aka - I would like to do the in code equivalent of right clicking a folder in file explorer...
4
by: palakwai_919 | last post by:
We have a Windows 2000 server with Beta 2 of the 2.0 Framework installed and the 1.1 Framework. For some odd reason when we hit our 2.0 Framework application we get the following error: Server...
3
by: Larry Serflaten | last post by:
I just put a simple exe out on the internet and tried to run it. All it does is manipulate its own images and respond to its own controls, but the darn thing needed FULL TRUST to run properly! ...
2
by: hecklar | last post by:
This is my first time posting here, so i apologize if i'm posting in the wrong subgroup or whatever, but here goes... I’m having a problem with threading and events (permissions?) in a VB.net...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
5
by: Control Freq | last post by:
Hi I connect to my MySQL database using MyODBC. I have a table called 'log' in a database called 'home'. When I try to do an insert like this: insert into log (userid,event,event_date) values...
1
by: beary | last post by:
Hello everyone, I'm not sure if this is the correct forum for this, and apologies for the length of this question, but I'm desperate for some good advice... I'm in way over my head with file...
2
by: beary | last post by:
Hello everyone, I posted this in unix/linux but it received no replies, so I assume it was the wrong forum. I'm trying here. I'm in way over my head with file permissions. The directory and...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.