Wednesday, March 28, 2012

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 .

SHi,

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" <Smith@.pricateemail.comwrote in message
news:%23yjQVIQMIHA.5224@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>
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
>
>


"Med" <nospam@.nowhere.nowherewrote in message
news:%236KXucQMIHA.4228@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

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
Hi,

Quote:

Originally Posted by

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/defaul...kb;en-us;306355
Hope it helps

Med

"Smith" <Smith@.pricateemail.comwrote in message
news:e5iA$HRMIHA.1208@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

>
"Med" <nospam@.nowhere.nowherewrote in message
news:%236KXucQMIHA.4228@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

>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
>


http://support.microsoft.com/kb/890960

0 comments:

Post a Comment