Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Global.asax file

Reply
Thread Tools

Global.asax file

 
 
paul downing via DotNetMonster.com
Guest
Posts: n/a
 
      12-15-2004
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:

<%@ Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.text" %>
<%@ Import Namespace="System.web" %>
<%@ Import Namespace="System.web.sessionstate" %>
<%@ Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.Text" %>
<script language="VB" runat="server">

Public Class Global
Inherits System.Web.HttpApplication

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)


Dim mail As New MailMessage()
Dim ErrorMessage = "The error description is as follows : " & Server.GetLastError.ToString
mail.To = ""
mail.Subject = "Error in the Site"
mail.Priority = MailPriority.High
mail.BodyFormat = MailFormat.Text
mail.Body = ErrorMessage
SmtpMail.Send(mail)

End Sub

End Class



i have even tried a simple reponse.write in the application_error and can't seem to make it trigger! Can someone point me in the right direction?

thanks

--
Message posted via http://www.dotnetmonster.com
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFoaXBhbCBSZWRkeQ==?=
Guest
Posts: n/a
 
      12-15-2004
hai paul,
Just Try giving SmtpServerName/IP it may help u

System.Web.Mail.MailMessage mailer = new System.Web.Mail.MailMessage();
mailer.To = ToAddress;
mailer.From = FromAddress;
mailer.Subject = Subject;
mailer.Body = Body;
SmtpMail.SmtpServer = SmtpServerName/IP
SmtpMail.Send(mailer);

Good Luck
Mahi

"paul downing via DotNetMonster.com" wrote:

> 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:
>
> <%@ Import Namespace="System.Web.Mail" %>
> <%@ Import Namespace="System.text" %>
> <%@ Import Namespace="System.web" %>
> <%@ Import Namespace="System.web.sessionstate" %>
> <%@ Import Namespace="System.Web.Mail" %>
> <%@ Import Namespace="System.Text" %>
> <script language="VB" runat="server">
>
> Public Class Global
> Inherits System.Web.HttpApplication
>
> Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
>
>
> Dim mail As New MailMessage()
> Dim ErrorMessage = "The error description is as follows : " & Server.GetLastError.ToString
> mail.To = ""
> mail.Subject = "Error in the Site"
> mail.Priority = MailPriority.High
> mail.BodyFormat = MailFormat.Text
> mail.Body = ErrorMessage
> SmtpMail.Send(mail)
>
> End Sub
>
> End Class
>
>
>
> i have even tried a simple reponse.write in the application_error and can't seem to make it trigger! Can someone point me in the right direction?
>
> thanks
>
> --
> Message posted via http://www.dotnetmonster.com
>

 
Reply With Quote
 
 
 
 
Juan T. Llibre [MVP]
Guest
Posts: n/a
 
      12-15-2004
Paul,

Check out sample code for this at
http://support.microsoft.com/default...b;en-us;308132

"How to Use the Application_Error Event"

You could send mail, instead of writing
to the log as the example does.



Juan T. Llibre
===========
"paul downing via DotNetMonster.com" <> wrote in
message news:2721f56ca0ed4f7182bb919f38a68bbc@DotNetMonste r.com...
> 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:
>
> <%@ Import Namespace="System.Web.Mail" %>
> <%@ Import Namespace="System.text" %>
> <%@ Import Namespace="System.web" %>
> <%@ Import Namespace="System.web.sessionstate" %>
> <%@ Import Namespace="System.Web.Mail" %>
> <%@ Import Namespace="System.Text" %>
> <script language="VB" runat="server">
>
> Public Class Global
> Inherits System.Web.HttpApplication
>
> Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
>
>
> Dim mail As New MailMessage()
> Dim ErrorMessage = "The error description is as follows : " &
> Server.GetLastError.ToString
> mail.To = ""
> mail.Subject = "Error in the Site"
> mail.Priority = MailPriority.High
> mail.BodyFormat = MailFormat.Text
> mail.Body = ErrorMessage
> SmtpMail.Send(mail)
>
> End Sub
>
> End Class
>
>
>
> i have even tried a simple reponse.write in the application_error and
> can't seem to make it trigger! Can someone point me in the right
> direction?
>
> thanks
>
> --
> Message posted via http://www.dotnetmonster.com



 
Reply With Quote
 
paul downing via DotNetMonster.com
Guest
Posts: n/a
 
      12-15-2004
thanks for the help guys....


i've now tried just this in my global.asax file and i just can't seem to trigger anything


<script language="VB">



Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
response.write("hello")
End Sub


</script>



any ideas?

--
Message posted via http://www.dotnetmonster.com
 
Reply With Quote
 
Juan T. Llibre [MVP]
Guest
Posts: n/a
 
      12-15-2004
Paul,

You cannot use Response.Write in global.asax

Where (in what page) would
the Response object write "hello" to ?



Juan T. Llibre
===========
"paul downing via DotNetMonster.com" <> wrote in
message news:8d76415388144314ab0da7f65a428d0b@DotNetMonste r.com...
> thanks for the help guys....
>
> i've now tried just this in my global.asax file and i just can't seem to
> trigger anything
>
> <script language="VB">
> Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
> response.write("hello")
> End Sub
> </script>
>
> any ideas?



 
Reply With Quote
 
pete
Guest
Posts: n/a
 
      12-15-2004
can you post the code that causes the error (or add one). if the originating
error is contained within a try / catch statement. you may need to rethrow
it for the application error event to fire

Cheers, pete

"paul downing via DotNetMonster.com" <> wrote in
message news:8d76415388144314ab0da7f65a428d0b@DotNetMonste r.com...
> thanks for the help guys....
>
>
> i've now tried just this in my global.asax file and i just can't seem to

trigger anything
>
>
> <script language="VB">
>
>
>
> Sub Application_Error(ByVal sender As Object, ByVal e As

EventArgs)
> response.write("hello")
> End Sub
>
>
> </script>
>
>
>
> any ideas?
>
> --
> Message posted via http://www.dotnetmonster.com



 
Reply With Quote
 
Juan T. Llibre [MVP]
Guest
Posts: n/a
 
      12-15-2004
Referencing the Session, Request, Response or Page
objects within application scope generates an error.

Application_Error only fires when an unhandled
exception is thrown, so you can't just Response.write
from it

You could *define* what happens when an
unhandled exception occurs, but you can't
do anything else within the Application_Error event.

Errors that are handled with error trapping
code (such as Try/Catch blocks) will *not*
cause the Application_Error event to fire.

It's impossible for response.write("hello")
to occur.within Application_Error.




Juan T. Llibre
===========
"pete" <> wrote in message
news:...
> can you post the code that causes the error (or add one). if the
> originating error is contained within a try / catch statement.
> you may need to rethrow it for the application error event to fire
>
> Cheers, pete
>
> "paul downing via DotNetMonster.com" <> wrote in
> message news:8d76415388144314ab0da7f65a428d0b@DotNetMonste r.com...
>> thanks for the help guys....
>>
>>
>> i've now tried just this in my global.asax file and i just can't seem to

> trigger anything
>>
>>
>> <script language="VB">
>>
>>
>>
>> Sub Application_Error(ByVal sender As Object, ByVal e As

> EventArgs)
>> response.write("hello")
>> End Sub
>>
>>
>> </script>
>>
>>
>>
>> any ideas?
>>
>> --
>> Message posted via http://www.dotnetmonster.com

>
>





 
Reply With Quote
 
paul downing via DotNetMonster.com
Guest
Posts: n/a
 
      12-16-2004
thanks for the pointers guys

--
Message posted via http://www.dotnetmonster.com
 
Reply With Quote
 
paul downing via DotNetMonster.com
Guest
Posts: n/a
 
      12-16-2004
right...

heres my page to generate an error when i click on the button..

<%@ Page Language="VB" %>
<script runat="server">

' Insert page code here
'

Sub Button1_Click(sender As Object, e As EventArgs)

throw(new ArgumentNullException())

End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:Button id="Button1" onclick="Button1_Click" runat="server" Text="Button"></asp:Button>
<!-- Insert content here -->
</form>
</body>
</html>
------------------------------------------------------------------>


and heres my global.asax file code....


<script language="VB">



Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
response.redirect("error.aspx")
End Sub


</script>

-----------------------------------------------
am i doing something wrong?

--
Message posted via http://www.dotnetmonster.com
 
Reply With Quote
 
paul downing via DotNetMonster.com
Guest
Posts: n/a
 
      12-16-2004
it works on my local virtual server.

--
Message posted via http://www.dotnetmonster.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting JPG file ppt file [Powerpoint] file zxcvar Digital Photography 7 06-22-2009 07:54 PM
Reading of file by next of map file and by next of file descriptor. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki C++ 1 07-10-2007 02:46 AM
How to create MDF file (.mdf) file from XML file. Dave ASP .Net 1 06-07-2007 11:32 PM
In file parsing, taking the first few characters of a text file after a readfile or streamreader file read... .Net Sports ASP .Net 11 01-17-2006 12:44 AM
An Automated process of watching a network file folder, reading a file in it and deleting the file using ASP.NET ? Luis Esteban Valencia Muņoz ASP .Net 3 06-04-2005 10:56 AM



Advertisments