473,757 Members | 9,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Global.asax Application_Err or not working?

I'm trying to get asp.net errors to write a entry in the server Application
log and have created an global.asax file and placed it in the root folder
where my web files reside but when I trigger an server error in some code I
do not get a log entry. The file contents are below. Any ideas why it does
not work?

<%@ Import Namespace="Syst em.Diagnostics" %>

<script language="C#" runat="server">

void Application_Err or(object sender, EventArgs e)

{

Exception objErr = Server.GetLastE rror().GetBaseE xception();

string err = "Error Caught in Application_Err or event\n" +

"Error in: " + Request.Url.ToS tring() +

"\nError Message:" + objErr.Message. ToString()+

"\nStack Trace:" + objErr.StackTra ce.ToString();

EventLog log = new EventLog();

log.Source = "myApplication" ;

log.WriteEntry( err, EventLogEntryTy pe.Error);

}

</script>
Nov 19 '05 #1
4 6146
Ron,
Did you actually create your event source? In order to begin logging, you
must first create the event source. This is more like registering an event
source for a specific event log.

Here's a sample for MSDN: (modified for your situation)

if(!EventLog.So urceExists("MyA pplication"))
{
EventLog.Create EventSource("My Application", "Applicatio n");
}

// then you can continue with your code:

EventLog log = new EventLog();
log.Source = "myApplication" ;
log.WriteEntry( err, EventLogEntryTy pe.Error);

Hope that Helps

Steve

"Ron Weldy" <ro******@msn.c om> wrote in message
news:ev******** ******@TK2MSFTN GP15.phx.gbl...
I'm trying to get asp.net errors to write a entry in the server
Application log and have created an global.asax file and placed it in the
root folder where my web files reside but when I trigger an server error
in some code I do not get a log entry. The file contents are below. Any
ideas why it does not work?

<%@ Import Namespace="Syst em.Diagnostics" %>

<script language="C#" runat="server">

void Application_Err or(object sender, EventArgs e)

{

Exception objErr = Server.GetLastE rror().GetBaseE xception();

string err = "Error Caught in Application_Err or event\n" +

"Error in: " + Request.Url.ToS tring() +

"\nError Message:" + objErr.Message. ToString()+

"\nStack Trace:" + objErr.StackTra ce.ToString();

EventLog log = new EventLog();

log.Source = "myApplication" ;

log.WriteEntry( err, EventLogEntryTy pe.Error);

}

</script>

Nov 19 '05 #2
Hi Steve,

Thanks for the tip. I tried but it didn't work. Interestingly enough, on
page 629 of Dino Esposito's Programming Microsoft ASP.NET he says "Your code
doesn't necessarily have to create the event source." He goes on to say it
will automatically place it in the application log so that's why I don't
have it in my code.

There is one thing I noticed and I am wondering if it could be the problem.
My 'application' does not have a name when the error page comes up in the
browser. It just says "Server Error in '/' Application." Could this be a
problem?

- Ron
"Steve Lutz" <sl***@nospam.c omcast.net> wrote in message
news:eY******** *******@TK2MSFT NGP12.phx.gbl.. .
Ron,
Did you actually create your event source? In order to begin logging, you
must first create the event source. This is more like registering an event
source for a specific event log.

Here's a sample for MSDN: (modified for your situation)

if(!EventLog.So urceExists("MyA pplication"))
{
EventLog.Create EventSource("My Application", "Applicatio n");
}

// then you can continue with your code:

EventLog log = new EventLog();
log.Source = "myApplication" ;
log.WriteEntry( err, EventLogEntryTy pe.Error);

Hope that Helps

Steve

"Ron Weldy" <ro******@msn.c om> wrote in message
news:ev******** ******@TK2MSFTN GP15.phx.gbl...
I'm trying to get asp.net errors to write a entry in the server
Application log and have created an global.asax file and placed it in the
root folder where my web files reside but when I trigger an server error
in some code I do not get a log entry. The file contents are below. Any
ideas why it does not work?

<%@ Import Namespace="Syst em.Diagnostics" %>

<script language="C#" runat="server">

void Application_Err or(object sender, EventArgs e)

{

Exception objErr = Server.GetLastE rror().GetBaseE xception();

string err = "Error Caught in Application_Err or event\n" +

"Error in: " + Request.Url.ToS tring() +

"\nError Message:" + objErr.Message. ToString()+

"\nStack Trace:" + objErr.StackTra ce.ToString();

EventLog log = new EventLog();

log.Source = "myApplication" ;

log.WriteEntry( err, EventLogEntryTy pe.Error);

}

</script>


Nov 19 '05 #3
Okay... I moved this code into a Page_Error event and found this error when
it tries to write to the log.

System.Security .SecurityExcept ion: Requested registry access is not
allowed.

What is the best practice on configuring security to allow writing to the
server logs? Or should I do something different?


"Ron Weldy" <ro******@msn.c om> wrote in message
news:ev******** ******@TK2MSFTN GP15.phx.gbl...
I'm trying to get asp.net errors to write a entry in the server
Application log and have created an global.asax file and placed it in the
root folder where my web files reside but when I trigger an server error
in some code I do not get a log entry. The file contents are below. Any
ideas why it does not work?

<%@ Import Namespace="Syst em.Diagnostics" %>

<script language="C#" runat="server">

void Application_Err or(object sender, EventArgs e)

{

Exception objErr = Server.GetLastE rror().GetBaseE xception();

string err = "Error Caught in Application_Err or event\n" +

"Error in: " + Request.Url.ToS tring() +

"\nError Message:" + objErr.Message. ToString()+

"\nStack Trace:" + objErr.StackTra ce.ToString();

EventLog log = new EventLog();

log.Source = "myApplication" ;

log.WriteEntry( err, EventLogEntryTy pe.Error);

}

</script>

Nov 19 '05 #4
Okay... I was able to solve this by using an existing event source, I just
picked "Active Server Pages" for now. I found that I can go into the
registry and add my own source if I want to but that is not high on the
priority list right now.

It's funny how the book I'm working with and the tech articles discussing
this technique dance around this subject. It would have been helpful if they
just stated the fact that you should use an existing source or just used an
existing source in the example instead of making it up. In fact in Dino's
book there is a big CAUTION about permissions but it talks about the event
logs not the event source. So there is my 2 cents....

So, Steve you were correct in your diagnosis but the real problem were the
permissions that the ASPNET account runs under.
"Ron Weldy" <ro******@msn.c om> wrote in message
news:%2******** *******@TK2MSFT NGP12.phx.gbl.. .
Hi Steve,

Thanks for the tip. I tried but it didn't work. Interestingly enough, on
page 629 of Dino Esposito's Programming Microsoft ASP.NET he says "Your
code doesn't necessarily have to create the event source." He goes on to
say it will automatically place it in the application log so that's why I
don't have it in my code.

There is one thing I noticed and I am wondering if it could be the
problem. My 'application' does not have a name when the error page comes
up in the browser. It just says "Server Error in '/' Application." Could
this be a problem?

- Ron
"Steve Lutz" <sl***@nospam.c omcast.net> wrote in message
news:eY******** *******@TK2MSFT NGP12.phx.gbl.. .
Ron,
Did you actually create your event source? In order to begin logging, you
must first create the event source. This is more like registering an
event source for a specific event log.

Here's a sample for MSDN: (modified for your situation)

if(!EventLog.So urceExists("MyA pplication"))
{
EventLog.Create EventSource("My Application", "Applicatio n");
}

// then you can continue with your code:

EventLog log = new EventLog();
log.Source = "myApplication" ;
log.WriteEntry( err, EventLogEntryTy pe.Error);

Hope that Helps

Steve

"Ron Weldy" <ro******@msn.c om> wrote in message
news:ev******** ******@TK2MSFTN GP15.phx.gbl...
I'm trying to get asp.net errors to write a entry in the server
Application log and have created an global.asax file and placed it in
the root folder where my web files reside but when I trigger an server
error in some code I do not get a log entry. The file contents are
below. Any ideas why it does not work?

<%@ Import Namespace="Syst em.Diagnostics" %>

<script language="C#" runat="server">

void Application_Err or(object sender, EventArgs e)

{

Exception objErr = Server.GetLastE rror().GetBaseE xception();

string err = "Error Caught in Application_Err or event\n" +

"Error in: " + Request.Url.ToS tring() +

"\nError Message:" + objErr.Message. ToString()+

"\nStack Trace:" + objErr.StackTra ce.ToString();

EventLog log = new EventLog();

log.Source = "myApplication" ;

log.WriteEntry( err, EventLogEntryTy pe.Error);

}

</script>



Nov 19 '05 #5

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

Similar topics

3
661
by: JP | last post by:
I need to be able to trap errors at the application level. I added this code to the Global.asax file. The code I wrote is supposed to get the last error that was generated and write to the event log as well as fire up my email class and generate an email to send me the error. But no matter what I do, I still get the icky looking yellow and white error screens. I’ve turned on customErrors in the web.config but not default URL setting....
3
3038
by: tafs7 | last post by:
My code below is supposed to email me when an error occurs on the application, but it's not emailing anything. Am I missing something? I know the smtp servers I've tried work. I even added a App_Start handler to see if I could get emailed at all even from the first request of the app, but to no avail. Could someone please help me out? Thanks a lot! --Thiago Web developer AgniTEK
5
1491
by: vbMental | last post by:
I am deep into a project and cannot get this to work correctly. I am trying to make a custom error page that will be able to know what exception occurred. I already know about the defaultRedirect page - <customErrors mode="on" defaultRedirect="Error.aspx"/> But how do I reference the exception that occurred from that page? If I cant, then should I use the Application_Error event in global.asax ? And if I do that, then what about hiding...
14
445
by: paul downing via DotNetMonster.com | last post by:
global file email send -------------------------------------------------------------------------------- guys, i'm developing an application and want to send an email with an error if it occurs to the administrator... i tried the following below but can't get it working. I did have it working a while ago...but have had no success with this.... any ideas? heres the code (simplistic) from the global.asax file:
9
2390
by: tshad | last post by:
I have an example I copied from "programming asp.net" (o'reilly) and can't seem to get the Sub (writefile) to execute. It displays all the response.write lines that are called directly, but not any of the response.write lines from inside the sub. ******************************************* <%@ Application Language="VB" %> <script runat="server">
2
2350
by: tshad | last post by:
I have my error handling set up in Global.asax: Sub Application_Error(Sender As Object, E as EventArgs) In this procedure I call a function in a dll that will write out to a history file. This works for some errors, but not others. If it doesn't work, it stops there and the normal MS error page goes to the User.
1
3310
by: Anonieko | last post by:
Global.asax? Use HttpModules Instead! In a previous post, I talked about HttpHandlers - an underused but incredibly useful feature of ASP.NET. Today I want to talk about HttpModules, which are probably more common than HttpHandlers, but could still stand to be advertised a bit more. HttpModules are incredibly easy to explain, so this will hopefully be a short-ish post. Simply put, HttpModules are portable versions of the global.asax....
19
10213
by: furiousmojo | last post by:
This is a strange problem. I have a project where the contents of global.asax application_error are not firing. It is an asp.net 2.0 application using web application projects. I have another app using web application projects and it's firing fine but it was upgraded from the 1.1 framework. Why doesn't my global.asax application_error routine fire?
1
1734
by: paulo | last post by:
Hello, I have a DLL library containing some web services which are declared in each .asmx file in the following way: <%@ WebService Language="C#" Class="LibraryName.WebService" %> I would like to log every unhandled exception that occurs on any web service declared in the library to a file. I noticed the global class, usually inside global.asax has the Application_Error event that can be
0
9489
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
9298
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
9906
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
9885
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
9737
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
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.