473,404 Members | 2,178 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Strange behaviour in Production environnement


Hello experts,

I have the following peice of code in my Global.asax

void Application_Error(object sender, EventArgs e)

{

//get reference to the source of the exception chain

Log log = new Log();

Exception ex = Server.GetLastError();

log.AddLogEntry(Request, ex);

log.SaveData();

Response.Redirect("~/Error.aspx");


}

This code works well on my test server Win2k3 , IIS 6. It write to my
erro.log text file and displays Error.aspx as expected.

In Production( Win2k3 , IIS 6) , it open the file error.log(Can be seen on
last modified date) but the expection is not written to the file. Neither is
Error.aspx displayed. Can someone tell were i should be looking?

Many thanks in advance .

S
Nov 27 '07 #1
4 1196
Med
Hi,

Does asp.net process has write /modify permission on the folder/file that
you are attemting to write? I would also use:
Server.ClearError(); before redirecting.
Regards
Med

"Smith" <Sm***@pricateemail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>
Hello experts,

I have the following peice of code in my Global.asax

void Application_Error(object sender, EventArgs e)

{

//get reference to the source of the exception chain

Log log = new Log();

Exception ex = Server.GetLastError();

log.AddLogEntry(Request, ex);

log.SaveData();

Response.Redirect("~/Error.aspx");


}

This code works well on my test server Win2k3 , IIS 6. It write to my
erro.log text file and displays Error.aspx as expected.

In Production( Win2k3 , IIS 6) , it open the file error.log(Can be seen on
last modified date) but the expection is not written to the file. Neither
is Error.aspx displayed. Can someone tell were i should be looking?

Many thanks in advance .

S


Nov 27 '07 #2

"Med" <no****@nowhere.nowherewrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi,

Does asp.net process has write /modify permission on the folder/file that
you are attemting to write? I would also use:
Server.ClearError(); before redirecting.
The user asp.net process is running under har full permission in the folder
where the code lives.Also note that the modified date of the error file
actually change according to the time error occured. It this was permission
problem, would it be allowed to actually open the file?
How does ServerClear() helps here?

Thanks
S
Nov 27 '07 #3
Med
Hi,
The user asp.net process is running under har full permission in the
folder where the code lives.
Does the log folder/file resides in this folder?

Actually Server.ClearError(); was irrelavant to your problem here, it was
just a suggestion as it prevents the error from continuing to the
Application_Error event handler.

Could you send the code for AddLogEntry(Request, ex)?

This is how I do it:

<%@ Import Namespace = "System.IO" %>
<%@ Import Namespace = "System.Diagnostics" %>

void Application_Error(object sender, EventArgs e)
{
//Only redirect to error page if in Release mode.
#if DEBUG
{
//Show error details
}
#else
{
try
{
LogError(Server.GetLastError().GetBaseException()) ;
Server.ClearError();
}
catch
{
//Do something.....
}

//Redirect to error.aspx page
Response.Redirect("error.aspx");
}
#endif
}

private void LogError(Exception objError)
{

try
{
string sLogFilePathAndName = String.Format(@"{0}{1} {2}.log",
Server.MapPath("~/Logs/"), DateTime.Now.ToLongDateString(),
DateTime.Now.DayOfWeek);
using (StreamWriter sw = File.AppendText(sLogFilePathAndName))
{
sw.WriteLine(Environment.NewLine);
sw.WriteLine(String.Format("Error Caught in Application on
{0} {1} @ {2}", DateTime.Now.DayOfWeek, DateTime.Now.ToLongDateString(),
DateTime.Now.ToLongTimeString()));
sw.WriteLine(String.Format("IP Address: {0}",
Request.ServerVariables["REMOTE_ADDR"].ToString()));
sw.WriteLine(String.Format("Platform: {0}",
Request.Browser.Platform));
sw.WriteLine(String.Format("Browser: {0}",
Request.Browser.Type));
sw.WriteLine(String.Format("Error in: {0}",
Request.Url.ToString()));
sw.WriteLine(String.Format("Error Message: {0}",
objError.Message.ToString()));
sw.WriteLine("Stack Trace:");
sw.WriteLine(objError.StackTrace.ToString());
sw.WriteLine(Environment.NewLine);
sw.WriteLine("-------------------------------------------------------------------------------------");
sw.Close();
}
}
catch
{
//Do something.....
}
}
You may also want to look at:
http://support.microsoft.com/default...b;en-us;306355
Hope it helps

Med

"Smith" <Sm***@pricateemail.comwrote in message
news:e5**************@TK2MSFTNGP05.phx.gbl...
>
"Med" <no****@nowhere.nowherewrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Hi,

Does asp.net process has write /modify permission on the folder/file that
you are attemting to write? I would also use:
Server.ClearError(); before redirecting.

The user asp.net process is running under har full permission in the
folder where the code lives.Also note that the modified date of the error
file actually change according to the time error occured. It this was
permission problem, would it be allowed to actually open the file?
How does ServerClear() helps here?

Thanks
S

Nov 27 '07 #4

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

Similar topics

3
by: Bill C. | last post by:
Hi, I've got a simple console app that just reads an XML file into a DataSet then prints out a description of each table in the DataSet, including column names and row values for each column. ...
7
by: Ziggy | last post by:
Just for curiosity. I know that main function is returning an int, but I came cross with the following code. (Unnessecary code is snipped) Is there any problem with it? #include <stdlib.h>...
0
by: theintrepidfox | last post by:
Dear Group I came accross a very annoying behaviour of Visual Studio, giving me six hours of headache till I found the solution. This post is mainly for fellow developers for reference as it...
13
by: oliv | last post by:
Bonjour, Je cherche le moyen d'utiliser une variable d'environnement dans les "Additional include directories" sous Visual C++ 6.0 mais je ne connais pas la syntaxe à utiliser. J'ai essayé...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.