473,770 Members | 6,322 Online
Bytes | Software Development & Data Engineering Community
+ 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: AllowPartiallyT rustedCallers]),
and as per MS instructions, the following attribute also:
[assembly: EventLogPermiss ion(SecurityAct ion.RequestMini mum,
PermissionAcces s = EventLogPermiss ionAccess.Instr ument)]
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;
EventLogEntryTy pe lEntry = EventLogEntryTy pe.Error;
EventLogPermiss ion oPerm;

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

Category = 0;
try
{
System.Text.Str ingBuilder oBuilder = new
System.Text.Str ingBuilder(LogT ext.Length + 100);

oBuilder.Append ("Date: ");
oBuilder.Append (System.DateTim e.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 EventLogPermiss ion(EventLogPer missionAccess.I nstrument,
sMachine);
oPerm.Assert();

if (!EventLog.Sour ceExists(Source ))
EventLog.Create EventSource(Sou rce, 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 sEventDescripti on = oBuilder.ToStri ng();

oLog.BeginInit( );
oLog.WriteEntry (sEventDescript ion, lEntry, EventID, Category);
oLog.EndInit();
}
bOK = true;
}
catch (System.Securit y.SecurityExcep tion secEx)
{
bOK = false;
throw(secEx);
}
catch (System.Excepti on ex)
{
bOK = false;
throw(ex);
}
finally
{
CodeAccessPermi ssion.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 .SecurityExcept ion: 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 EventLogPermiss ion?
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 1304

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

Similar topics

1
3338
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 from VBScript to C# (*.vbs --> *.cs). Does C# have a native method for doing what MSWC.PermissionChecker used to do? If so has anyone gone through converting the MSWC.PermissionChecker method to C# and would they share what they did? If not...
4
2695
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 and granting read/write access to a specific user {not the user running the program}. Any ideas? Or am I going to have to PInvoke like crazy??
4
11785
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 Application Unavailable The web application you are attempting to access on this web server is currently unavailable. Please hit the "Refresh" button in your web browser to retry your request. Administrator Note: An error message detailing the...
3
1352
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! Does VS.NET have some sort of method to spit out warnings when stepping outside of the trust boundries? The trace on the security screen pointed to a few routines, but I don't know what in the routine was causing problems. Is there a way I can...
2
1419
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 Windows application (background service). I’m trying to write an application that processes files, launching a new thread for each file that is dropped into a certain folder. Now, the application works like a charm on my Win2000 machine, but...
15
4642
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 communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
5
2252
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 (blah blah.... I get this error response from MySQL: You have an error in your SQL syntax; check the manual that corresponds
1
2227
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 permissions. The directory and files are sitting on a linux server. I know almost nothing about linux. The background: I was given a web share by my IT admin. Initially, the web share had 3 users, myself (as the owner) ,root (the group) and...
2
2049
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 files are sitting on a linux server. I know almost nothing about linux. The background: I was given a web share by my IT admin. Initially, the web share had 3 users, myself (as the owner) ,root (the group) and everyone. I could copy and paste from my...
0
9591
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10053
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10001
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9867
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8880
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3573
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2816
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.