473,387 Members | 1,464 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,387 software developers and data experts.

DefaultRedirect Problem

When using an ASPX page for a DefaultRedirect it does not work if the ASPX
page has any code in it.

If I put ...

If Not IsPostBack Then
lblMessage.Text = Server.GetLastError.Message
End If

in the ASPX page it does not display when an unhandled exception is thrown.
If I take the code out, the ASPX page displays properly when an unhandled
exception is thrown.

Does anyone know why this occurs?
Thanks,
G
Nov 18 '05 #1
21 2668
I believe you need server.clearerror after getlast error call. != 100% sure
on this

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Gary" <gb@nospam.com> wrote in message
news:OZ**************@TK2MSFTNGP09.phx.gbl...
When using an ASPX page for a DefaultRedirect it does not work if the ASPX
page has any code in it.

If I put ...

If Not IsPostBack Then
lblMessage.Text = Server.GetLastError.Message
End If

in the ASPX page it does not display when an unhandled exception is thrown. If I take the code out, the ASPX page displays properly when an unhandled
exception is thrown.

Does anyone know why this occurs?
Thanks,
G

Nov 18 '05 #2
Hi Gary,
Thanks for posting in the community!
From your description, you used a custom error page( a asp.net aspx page)
and set in the web.config via the
<customErrors defaultRedirect="CustomErrorPage.aspx" mode="On">
</customErrors>
so as to use the certain aspx page as the default error page. However, you
encoutered runtime error when execute and redirect to the error page, yes?
If there is anything I misunderstood, please feel free to let me know.

Based on my research, this problem is due to the Server's LastError has
already been cleared before the CustomError Page is loaded. For example, if
you add the below code in your custom error aspx page:

if(!IsPostBack)
{
Exception exp = Server.GetLastError();

if(exp != null)
{
lblMessage.Text = exp.Message;
}
}

we can find that the "exp" is always an empty object, so the server error
has been cleared up. So if we use Server.GetLastError().Message to retrieve
info from it, we'll get exception.
And One way to keep the server error information so as to be used in the
Custom error page is to pre-store the error's information before the custom
error page is loaded. For example, in the "Application_Error" event of the
Global class:
protected void Application_Error(Object sender, EventArgs e)
{
Session["Last_Error_Info"] = Server.GetLastError().Message;
}

Then, in the custom error page, we can retrieve the info from the Session
so as to output it on the custom error page, such as:

public class CustomErrorPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblMessage;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
string msg = (string)Session["Last_Error_Info"];

if(msg != null)
{
lblMessage.Text = msg;
}
}

}

..........................
}
Please check out my suggestion to see whether it helps you. If you feel
anything unclear or have any questions, please always feel free to let me
know.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
Hi Gary,
After some further research, I found that the problem (can not retrieve the
error info via Server.GetLastError) was caused by the default behavior when
the ASP.NET runtime handling the unhandled exceptions. In fact, after the
"Application_Error" event, the ASP.NET runtime will clear the server error
and then direct user to the custom error page(if the setting is to use
custome error page), however, at that time ,since the server error is
cleared, so we are not able to retrieve it in the custom error page's
Page_Load event.

And in the last reply, I told you that we can store the error info in
Session and then retrieve from the Session again in Custom error page's
Page_Load. However, after testing this means, I found it also impossible
because after the Application_Error, the current Session will be stoped and
a new Session is to be started, so all the infos stored in Session also
losed. But I've found another way to retrieve the Server Error info in
custom error page's Page_Load event:
Just manually use "Server.Transfer" to forward the current response to the
Custom error page, that'll cause the error info still remain. For example,
here is the code I tested and succeeded:
event to custom error page 's Page_Load event:

##in Application_Error:
protected void Application_Error(Object sender, EventArgs e)
{
Exception ex = Server.GetLastError();

HttpContext.Current.Response.Clear();
Server.Transfer("CustomErrorPage.aspx");
}

##in CustomErrorPage.aspx 's code behind
public class CustomErrorPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblCallStack;
protected System.Web.UI.WebControls.Label lblSource;
protected System.Web.UI.WebControls.Label lblMessage;

private void Page_Load(object sender, System.EventArgs e)
{
Exception ex = Server.GetLastError();
lblMessage.Text = ex.Message;
lblCallStack.Text = ex.StackTrace;
lblSource.Text = ex.Source;
}
....................
}

I manually forward the request to the custom erro page rather than let the
ASP.NET runtime do the default hehavior.

In addition, here is a tech article on providing custom error handing and
reporting:

#Rich Custom Error Handling with ASP.NET
http://msdn.microsoft.com/library/en...rs.asp?frame=t
rue

Please try out the above suggestions. If you feel anything unclear, please
feel free to let me know.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #4
Steven:

Thanks. Once I did the following in the application error event....
Dim unhandledException As Exception = _
Server.GetLastError().InnerException
Application("LastErrorMessage") = unhandledException.Message
Then it all worked fine. thanks for your help.

Gary
"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:qz**************@cpmsftngxa07.phx.gbl...
Hi Gary,
Thanks for posting in the community!
From your description, you used a custom error page( a asp.net aspx page)
and set in the web.config via the
<customErrors defaultRedirect="CustomErrorPage.aspx" mode="On">
</customErrors>
so as to use the certain aspx page as the default error page. However, you
encoutered runtime error when execute and redirect to the error page, yes?
If there is anything I misunderstood, please feel free to let me know.

Based on my research, this problem is due to the Server's LastError has
already been cleared before the CustomError Page is loaded. For example, if you add the below code in your custom error aspx page:

if(!IsPostBack)
{
Exception exp = Server.GetLastError();

if(exp != null)
{
lblMessage.Text = exp.Message;
}
}

we can find that the "exp" is always an empty object, so the server error
has been cleared up. So if we use Server.GetLastError().Message to retrieve info from it, we'll get exception.
And One way to keep the server error information so as to be used in the
Custom error page is to pre-store the error's information before the custom error page is loaded. For example, in the "Application_Error" event of the
Global class:
protected void Application_Error(Object sender, EventArgs e)
{
Session["Last_Error_Info"] = Server.GetLastError().Message;
}

Then, in the custom error page, we can retrieve the info from the Session
so as to output it on the custom error page, such as:

public class CustomErrorPage : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblMessage;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
string msg = (string)Session["Last_Error_Info"];

if(msg != null)
{
lblMessage.Text = msg;
}
}

}

.........................
}
Please check out my suggestion to see whether it helps you. If you feel
anything unclear or have any questions, please always feel free to let me
know.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #5
Hi Gary,
Thanks for your followup. I'm glad that you've figured out the means to
workaround this problem. However, since you used the Application State to
store the ServerError Info, and the server error may occcurs in every
requested thread, so there exist some potential concurrency issue on the
application state object. For example, multi user are visiting the site and
some of them encountered some serverside error. Then, all these thread will
try accessing the application's certain object. If you haven't explictly
provide concurrency protection on the application object, there will occur
concurrent issue. So do remember to explicitly provide synthronism
operations when accessing application object. For example, using the below
style code:
Application.Lock();

Application["error_info"] = Server.GetLastError().Message;

Application.UnLock();

And here is the description in MSDN on using the Application State
object(focus on concurrency issue):
----------------------------
The concurrency and synchronization implications of storing and accessing a
global variable within a multithreaded server environment. Multiple threads
within an application can access values stored in application state
simultaneously. You should always be careful to ensure that if an
application-scoped object is free-threaded, it contains built-in
synchronization support. All custom objects that target the common language
runtime are free-threaded. If an application-scoped object is not
free-threaded, you must ensure that explicit synchronization methods are
coded around it to avoid deadlocks, race conditions, and access violations.
----------------------------
For detailed info on using Application State, you may view the following
reference in MSDN:

#Application State
http://msdn.microsoft.com/library/en...icationState.a
sp?frame=true

And here is a tech article on the concurrency issues of the Application
object in ASP, I also think it helpful to you since the situation is
similar in ASP.NET.

#Application Concurrency Issues
http://msdn.microsoft.com/library/en...ionconcurrency
issues.asp?frame=true

In addtion, if you'd like to use other means to accomplish tranmiting the
server error info to custom error page, you may
have a further check on the suggestions in my former reply and if you have
any questions on it, please feel free to let me know.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #6
Steven

Would you be able to convert this into VB for me, I understand what you are doing, I just don't know how to replicate it in V

----- Steven Cheng[MSFT] wrote: ----

Hi Gary
After some further research, I found that the problem (can not retrieve the
error info via Server.GetLastError) was caused by the default behavior when
the ASP.NET runtime handling the unhandled exceptions. In fact, after the
"Application_Error" event, the ASP.NET runtime will clear the server error
and then direct user to the custom error page(if the setting is to use
custome error page), however, at that time ,since the server error is
cleared, so we are not able to retrieve it in the custom error page's
Page_Load event

And in the last reply, I told you that we can store the error info in
Session and then retrieve from the Session again in Custom error page's
Page_Load. However, after testing this means, I found it also impossible
because after the Application_Error, the current Session will be stoped and
a new Session is to be started, so all the infos stored in Session also
losed. But I've found another way to retrieve the Server Error info in
custom error page's Page_Load event
Just manually use "Server.Transfer" to forward the current response to the
Custom error page, that'll cause the error info still remain. For example,
here is the code I tested and succeeded
event to custom error page 's Page_Load event

##in Application_Error
protected void Application_Error(Object sender, EventArgs e

Exception ex = Server.GetLastError()

HttpContext.Current.Response.Clear()
Server.Transfer("CustomErrorPage.aspx")
##in CustomErrorPage.aspx 's code behin
public class CustomErrorPage : System.Web.UI.Pag

protected System.Web.UI.WebControls.Label lblCallStack
protected System.Web.UI.WebControls.Label lblSource
protected System.Web.UI.WebControls.Label lblMessage

private void Page_Load(object sender, System.EventArgs e

Exception ex = Server.GetLastError();
lblMessage.Text = ex.Message
lblCallStack.Text = ex.StackTrace
lblSource.Text = ex.Source;

...................
I manually forward the request to the custom erro page rather than let the
ASP.NET runtime do the default hehavior

In addition, here is a tech article on providing custom error handing and
reporting

#Rich Custom Error Handling with ASP.NE
http://msdn.microsoft.com/library/en...ors.asp?frame=
ru

Please try out the above suggestions. If you feel anything unclear, please
feel free to let me know


Regards

Steven Chen
Microsoft Online Suppor

Get Secure! www.microsoft.com/securit
(This posting is provided "AS IS", with no warranties, and confers no
rights.

Nov 18 '05 #7
Hi,

Here is a webpage which can help convert C# code into VB.NET:

http://authors.aspalliance.com/aldot...translate.aspx

Hope this helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #8
Steven

I'm still having problems with your example. I'll give you some more detail as to what I'm doing

In the Application_Start event in the global.axax I try and create an object of clsBackoffic

Dim BO as new clsBackoffic

I inentionally throw an exception back to the global.axa

I then follow your example in the Application_Err even
Dim ex As Exception = Server.GetLastErro
At this point I check to make sure that it is the exception that I have thrown before the server.transfer("errors.aspx"
HttpContext.Current.Response.Clear(
Server.Transfer("Errors.aspx"

Here's the proble

In the page_load event I put the code per your exampl

Dim ex As Exception = Server.GetLastErro
At this point I check the exception again at the command window and recieve this message
Referenced object has a value of 'Nothing'. So when you run the next line of code it will generate another exception when you try to set the text property of the label to the message property of the exception
lblErrMsg.Text = ex.Messag

Any clues

Thanks
Ken

Nov 18 '05 #9
Hi,

It's really strange since I put the same code as you in my web app(I tested
in both C# and VB.NETweb projects) and it worked well. Would you have a
try creating a new simple web project and test it again? This time, to make
it more simple, you may just put the following in the Application_Error:

Server.Transfer("Errors.aspx")

Also, don't forget the
<customErrors defaultRedirect="CustomErrorPage.aspx" mode="On" />
in the web.config file.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #10
Steven

Would you be able to convert this into VB for me, I understand what you are doing, I just don't know how to replicate it in V

----- Steven Cheng[MSFT] wrote: ----

Hi Gary
After some further research, I found that the problem (can not retrieve the
error info via Server.GetLastError) was caused by the default behavior when
the ASP.NET runtime handling the unhandled exceptions. In fact, after the
"Application_Error" event, the ASP.NET runtime will clear the server error
and then direct user to the custom error page(if the setting is to use
custome error page), however, at that time ,since the server error is
cleared, so we are not able to retrieve it in the custom error page's
Page_Load event

And in the last reply, I told you that we can store the error info in
Session and then retrieve from the Session again in Custom error page's
Page_Load. However, after testing this means, I found it also impossible
because after the Application_Error, the current Session will be stoped and
a new Session is to be started, so all the infos stored in Session also
losed. But I've found another way to retrieve the Server Error info in
custom error page's Page_Load event
Just manually use "Server.Transfer" to forward the current response to the
Custom error page, that'll cause the error info still remain. For example,
here is the code I tested and succeeded
event to custom error page 's Page_Load event

##in Application_Error
protected void Application_Error(Object sender, EventArgs e

Exception ex = Server.GetLastError()

HttpContext.Current.Response.Clear()
Server.Transfer("CustomErrorPage.aspx")
##in CustomErrorPage.aspx 's code behin
public class CustomErrorPage : System.Web.UI.Pag

protected System.Web.UI.WebControls.Label lblCallStack
protected System.Web.UI.WebControls.Label lblSource
protected System.Web.UI.WebControls.Label lblMessage

private void Page_Load(object sender, System.EventArgs e

Exception ex = Server.GetLastError();
lblMessage.Text = ex.Message
lblCallStack.Text = ex.StackTrace
lblSource.Text = ex.Source;

...................
I manually forward the request to the custom erro page rather than let the
ASP.NET runtime do the default hehavior

In addition, here is a tech article on providing custom error handing and
reporting

#Rich Custom Error Handling with ASP.NE
http://msdn.microsoft.com/library/en...ors.asp?frame=
ru

Please try out the above suggestions. If you feel anything unclear, please
feel free to let me know


Regards

Steven Chen
Microsoft Online Suppor

Get Secure! www.microsoft.com/securit
(This posting is provided "AS IS", with no warranties, and confers no
rights.

Nov 18 '05 #11
Hi,

Here is a webpage which can help convert C# code into VB.NET:

http://authors.aspalliance.com/aldot...translate.aspx

Hope this helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #12
Steven

I'm still having problems with your example. I'll give you some more detail as to what I'm doing

In the Application_Start event in the global.axax I try and create an object of clsBackoffic

Dim BO as new clsBackoffic

I inentionally throw an exception back to the global.axa

I then follow your example in the Application_Err even
Dim ex As Exception = Server.GetLastErro
At this point I check to make sure that it is the exception that I have thrown before the server.transfer("errors.aspx"
HttpContext.Current.Response.Clear(
Server.Transfer("Errors.aspx"

Here's the proble

In the page_load event I put the code per your exampl

Dim ex As Exception = Server.GetLastErro
At this point I check the exception again at the command window and recieve this message
Referenced object has a value of 'Nothing'. So when you run the next line of code it will generate another exception when you try to set the text property of the label to the message property of the exception
lblErrMsg.Text = ex.Messag

Any clues

Thanks
Ken

Nov 18 '05 #13
Hi,

It's really strange since I put the same code as you in my web app(I tested
in both C# and VB.NETweb projects) and it worked well. Would you have a
try creating a new simple web project and test it again? This time, to make
it more simple, you may just put the following in the Application_Error:

Server.Transfer("Errors.aspx")

Also, don't forget the
<customErrors defaultRedirect="CustomErrorPage.aspx" mode="On" />
in the web.config file.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #14
Steven

Would you be able to convert this into VB for me, I understand what you are doing, I just don't know how to replicate it in V

----- Steven Cheng[MSFT] wrote: ----

Hi Gary
After some further research, I found that the problem (can not retrieve the
error info via Server.GetLastError) was caused by the default behavior when
the ASP.NET runtime handling the unhandled exceptions. In fact, after the
"Application_Error" event, the ASP.NET runtime will clear the server error
and then direct user to the custom error page(if the setting is to use
custome error page), however, at that time ,since the server error is
cleared, so we are not able to retrieve it in the custom error page's
Page_Load event

And in the last reply, I told you that we can store the error info in
Session and then retrieve from the Session again in Custom error page's
Page_Load. However, after testing this means, I found it also impossible
because after the Application_Error, the current Session will be stoped and
a new Session is to be started, so all the infos stored in Session also
losed. But I've found another way to retrieve the Server Error info in
custom error page's Page_Load event
Just manually use "Server.Transfer" to forward the current response to the
Custom error page, that'll cause the error info still remain. For example,
here is the code I tested and succeeded
event to custom error page 's Page_Load event

##in Application_Error
protected void Application_Error(Object sender, EventArgs e

Exception ex = Server.GetLastError()

HttpContext.Current.Response.Clear()
Server.Transfer("CustomErrorPage.aspx")
##in CustomErrorPage.aspx 's code behin
public class CustomErrorPage : System.Web.UI.Pag

protected System.Web.UI.WebControls.Label lblCallStack
protected System.Web.UI.WebControls.Label lblSource
protected System.Web.UI.WebControls.Label lblMessage

private void Page_Load(object sender, System.EventArgs e

Exception ex = Server.GetLastError();
lblMessage.Text = ex.Message
lblCallStack.Text = ex.StackTrace
lblSource.Text = ex.Source;

...................
I manually forward the request to the custom erro page rather than let the
ASP.NET runtime do the default hehavior

In addition, here is a tech article on providing custom error handing and
reporting

#Rich Custom Error Handling with ASP.NE
http://msdn.microsoft.com/library/en...ors.asp?frame=
ru

Please try out the above suggestions. If you feel anything unclear, please
feel free to let me know


Regards

Steven Chen
Microsoft Online Suppor

Get Secure! www.microsoft.com/securit
(This posting is provided "AS IS", with no warranties, and confers no
rights.

Nov 18 '05 #15
Steven

Would you be able to convert this into VB for me, I understand what you are doing, I just don't know how to replicate it in V

----- Steven Cheng[MSFT] wrote: ----

Hi Gary
After some further research, I found that the problem (can not retrieve the
error info via Server.GetLastError) was caused by the default behavior when
the ASP.NET runtime handling the unhandled exceptions. In fact, after the
"Application_Error" event, the ASP.NET runtime will clear the server error
and then direct user to the custom error page(if the setting is to use
custome error page), however, at that time ,since the server error is
cleared, so we are not able to retrieve it in the custom error page's
Page_Load event

And in the last reply, I told you that we can store the error info in
Session and then retrieve from the Session again in Custom error page's
Page_Load. However, after testing this means, I found it also impossible
because after the Application_Error, the current Session will be stoped and
a new Session is to be started, so all the infos stored in Session also
losed. But I've found another way to retrieve the Server Error info in
custom error page's Page_Load event
Just manually use "Server.Transfer" to forward the current response to the
Custom error page, that'll cause the error info still remain. For example,
here is the code I tested and succeeded
event to custom error page 's Page_Load event

##in Application_Error
protected void Application_Error(Object sender, EventArgs e

Exception ex = Server.GetLastError()

HttpContext.Current.Response.Clear()
Server.Transfer("CustomErrorPage.aspx")
##in CustomErrorPage.aspx 's code behin
public class CustomErrorPage : System.Web.UI.Pag

protected System.Web.UI.WebControls.Label lblCallStack
protected System.Web.UI.WebControls.Label lblSource
protected System.Web.UI.WebControls.Label lblMessage

private void Page_Load(object sender, System.EventArgs e

Exception ex = Server.GetLastError();
lblMessage.Text = ex.Message
lblCallStack.Text = ex.StackTrace
lblSource.Text = ex.Source;

...................
I manually forward the request to the custom erro page rather than let the
ASP.NET runtime do the default hehavior

In addition, here is a tech article on providing custom error handing and
reporting

#Rich Custom Error Handling with ASP.NE
http://msdn.microsoft.com/library/en...ors.asp?frame=
ru

Please try out the above suggestions. If you feel anything unclear, please
feel free to let me know


Regards

Steven Chen
Microsoft Online Suppor

Get Secure! www.microsoft.com/securit
(This posting is provided "AS IS", with no warranties, and confers no
rights.

Nov 18 '05 #16
Hi,

Here is a webpage which can help convert C# code into VB.NET:

http://authors.aspalliance.com/aldot...translate.aspx

Hope this helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #17
Hi,

Here is a webpage which can help convert C# code into VB.NET:

http://authors.aspalliance.com/aldot...translate.aspx

Hope this helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #18
Steven

I'm still having problems with your example. I'll give you some more detail as to what I'm doing

In the Application_Start event in the global.axax I try and create an object of clsBackoffic

Dim BO as new clsBackoffic

I inentionally throw an exception back to the global.axa

I then follow your example in the Application_Err even
Dim ex As Exception = Server.GetLastErro
At this point I check to make sure that it is the exception that I have thrown before the server.transfer("errors.aspx"
HttpContext.Current.Response.Clear(
Server.Transfer("Errors.aspx"

Here's the proble

In the page_load event I put the code per your exampl

Dim ex As Exception = Server.GetLastErro
At this point I check the exception again at the command window and recieve this message
Referenced object has a value of 'Nothing'. So when you run the next line of code it will generate another exception when you try to set the text property of the label to the message property of the exception
lblErrMsg.Text = ex.Messag

Any clues

Thanks
Ken

Nov 18 '05 #19
Steven

I'm still having problems with your example. I'll give you some more detail as to what I'm doing

In the Application_Start event in the global.axax I try and create an object of clsBackoffic

Dim BO as new clsBackoffic

I inentionally throw an exception back to the global.axa

I then follow your example in the Application_Err even
Dim ex As Exception = Server.GetLastErro
At this point I check to make sure that it is the exception that I have thrown before the server.transfer("errors.aspx"
HttpContext.Current.Response.Clear(
Server.Transfer("Errors.aspx"

Here's the proble

In the page_load event I put the code per your exampl

Dim ex As Exception = Server.GetLastErro
At this point I check the exception again at the command window and recieve this message
Referenced object has a value of 'Nothing'. So when you run the next line of code it will generate another exception when you try to set the text property of the label to the message property of the exception
lblErrMsg.Text = ex.Messag

Any clues

Thanks
Ken

Nov 18 '05 #20
Hi,

It's really strange since I put the same code as you in my web app(I tested
in both C# and VB.NETweb projects) and it worked well. Would you have a
try creating a new simple web project and test it again? This time, to make
it more simple, you may just put the following in the Application_Error:

Server.Transfer("Errors.aspx")

Also, don't forget the
<customErrors defaultRedirect="CustomErrorPage.aspx" mode="On" />
in the web.config file.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #21
Hi,

It's really strange since I put the same code as you in my web app(I tested
in both C# and VB.NETweb projects) and it worked well. Would you have a
try creating a new simple web project and test it again? This time, to make
it more simple, you may just put the following in the Application_Error:

Server.Transfer("Errors.aspx")

Also, don't forget the
<customErrors defaultRedirect="CustomErrorPage.aspx" mode="On" />
in the web.config file.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #22

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

Similar topics

2
by: gilberto ramirez | last post by:
I want to create an ASP application in the following way: PC1 - Windows XP (SP1) with VS .NET (and everything needed) - im programming with C# .NET SRV1 - ISA SERVER - Windows 2000 (SP3) SRV2...
6
by: Gary | last post by:
I have the following in my web.config.... <customErrors mode="RemoteOnly" defaultRedirect="Applicationerror.aspx"/> but, my error page does not display. Instead a 'Runtime Error' page...
11
by: James Warren | last post by:
I just installed VB.net 2003, upgrading from VB6. I tried to open a new ASP.net Web Application and immediately got an error stating that my Web Server isn't running ASP.net version 1.1. I tried...
1
by: Nathan Sokalski | last post by:
I have retrieved data from a database using a SELECT statement that includes an INNER JOIN. The data seems to be retrieved to the DataSet OK, but I am having trouble getting the data from the...
0
by: raja | last post by:
Hi, I want to upload one file from network,which it was not working but when i try to upload the same file from server system it is working. Is there any problems with network settings? I...
0
by: aj123 | last post by:
Hello; I develop website and uploaded to host provider and works fine but I uploaded it to ther hosting provider and it not working and give this problem ----- Runtime Error Description: An...
4
by: =?Utf-8?B?TWFyaw==?= | last post by:
I think I am missing something about how to redirect to a certain page when 404 errors occur. I want to redirect to a generic pagenotfound.aspx page. I have the following in web.config: ...
6
by: khanpmd | last post by:
Hi , I have a doubt in ASP.Net hosting.I have developed a site and hosted it. when i browse that site an error occured like this.I dont know why this error is showing? Because i have no problem...
6
by: praveenb000 | last post by:
we hosted a website http://vijayawadanalanda.org developed using asp.net and back end MS Accees database. There is some database connectivity problem occurring when saving the information in...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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
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...

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.