[ASP][C#] pb with aspxerrorpath

J

julien

This is a part of my Global.asax.cs :

Code:
protected void Application_Error(Object sender, EventArgs e)
{

String sError =
Server.GetLastError().GetBaseException().Message;
Context.Response.Redirect("ErrorViewer.aspx?" + "Error=" +
HttpUtility.UrlEncode(sError));
}

and of my web.config :

Code:
<customErrors mode="On" defaultRedirect="ErrorViewer.aspx"/>

and at least of the ErrorViewer.aspx.cs :

Code:

protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
if (Context.Request.Params["Error"] != null)
{
String ErrorMessage =
HttpUtility.UrlDecode(Context.Request.Params["Error"]);
if (ErrorMessage.StartsWith("Login failed") ||
ErrorMessage.StartsWith("Invalid authorization
specification"))
{
Context.Response.Redirect("Default.aspx");
}
else
{
Label1.Text = ErrorMessage;
}
}
else
{
Label1.Text = "Unknown error.";
}
}

On my development server and integration server, whenever I have an
error, I am well redirected to :
http://server/MyWebSite/ErrorViewer.aspx?Error=Attempt+to+insert+duplicate+key#edit

But on my production server, I am redirected to :
http://server/MyWebSite/ErrorViewer.aspx?aspxerrorpath=/MyWebSite/TranscoDealingCenter.aspx#edit

Knowing that TranscoDealingCenter.aspx is the page from which the
error has been generated.
I don't understand the particular behaviour that I have in production.
I have checked and it seems that the ASPNET account has got the same
rights on all the environments, it is part of the same user group.
However, it seems that there is a server setting difference, but I
have absolutely no idea which one it can be. Indeed, in one case I go
through the Application_Error of the global.asax except in
production...
Thanks for your help.
JULIEN
 
T

Tampa.NET Koder

Yeah. I'm surprise you didn't end up in a endless loop. The
Applicaiton_Error is supposed to be used for logging unhandled exceptions
and at this point the only thing you can do is log to a file or a database.

So, don't redirect users to a new page in this event handler, thats what the
custom errors are for.
 
J

julien

Thanks for your help.
Actually, the way I have setup my loggin maangement is right because I
have discovered that between String sError =
Server.GetLastError().GetBaseException().Message; and my redirection
(not a transfer by the way) I have a Trace.Writeline that I didn't
show at the beginning because I thought it was useless, but I am
pretty sure that this is what causes an exception (for a reason that I
still try to determine (some rights pb or IIS configuration pb)), and
then I go to the web.config error handling.
By the way again, msdn says that it is common to use a redirect in the
Applicatio_Error in order to stop the Error to go further, which is
what I want actually.
JULIEN



Tampa.NET Koder said:
Yeah. I'm surprise you didn't end up in a endless loop. The
Applicaiton_Error is supposed to be used for logging unhandled exceptions
and at this point the only thing you can do is log to a file or a database.

So, don't redirect users to a new page in this event handler, thats what the
custom errors are for.


julien said:
This is a part of my Global.asax.cs :

Code:
protected void Application_Error(Object sender, EventArgs e)
{

String sError =
Server.GetLastError().GetBaseException().Message;
Context.Response.Redirect("ErrorViewer.aspx?" + "Error=" +
HttpUtility.UrlEncode(sError));
}

and of my web.config :

Code:
<customErrors mode="On" defaultRedirect="ErrorViewer.aspx"/>

and at least of the ErrorViewer.aspx.cs :

Code:

protected System.Web.UI.WebControls.Label Label1;

private void Page_Load(object sender, System.EventArgs e)
{
if (Context.Request.Params["Error"] != null)
{
String ErrorMessage =
HttpUtility.UrlDecode(Context.Request.Params["Error"]);
if (ErrorMessage.StartsWith("Login failed") ||
ErrorMessage.StartsWith("Invalid authorization
specification"))
{
Context.Response.Redirect("Default.aspx");
}
else
{
Label1.Text = ErrorMessage;
}
}
else
{
Label1.Text = "Unknown error.";
}
}

On my development server and integration server, whenever I have an
error, I am well redirected to :
http://server/MyWebSite/ErrorViewer.aspx?Error=Attempt+to+insert+duplicate+key#edit

But on my production server, I am redirected to :
http://server/MyWebSite/ErrorViewer.aspx?aspxerrorpath=/MyWebSite/TranscoDealingCenter.aspx#edit

Knowing that TranscoDealingCenter.aspx is the page from which the
error has been generated.
I don't understand the particular behaviour that I have in production.
I have checked and it seems that the ASPNET account has got the same
rights on all the environments, it is part of the same user group.
However, it seems that there is a server setting difference, but I
have absolutely no idea which one it can be. Indeed, in one case I go
through the Application_Error of the global.asax except in
production...
Thanks for your help.
JULIEN
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top