473,325 Members | 2,816 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,325 software developers and data experts.

Custom error web pages problem

This is what i am trying to do

I have a DAL that contains all of my database connections/reads etc.

I have a separate GUI layer that has my web pages

I would like to pass my exception errors in my DAL to a custom web page to
display to the user.

Here is what I have done so far

1. Created a CustomError web page that displays the error to the user in a
friendly format
2. Modified my Global.asax file to caputre the error and put it in a
Session variable.
3. Modified my Web.Config file to on error redirect my user to a custom
error page.

Problem - my error page comes up but there is no message being returned

Here is the code that I am using:

An example DAL code block throwing the exception

Public Function GetAllLevel1(ByVal ds As DataSet)

Dim myConnection As New
SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings("PMADataAccess"))
Dim myCommand As New SqlDataAdapter("sp_SelectAllLevel1",
myConnection)
Try
myCommand.Fill(ds, "AllLevel1")
Catch ex As Exception
Throw New System.Exception(ex.Message.ToString)
End Try
myConnection.Close()
Return ds
End Function

In Global.asax

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim LastError As Exception
LastError = Server.GetLastError()
Session("CurrentError") = LastError.Message
End Sub

In my Web.config file

<customErrors mode="On" defaultRedirect="GUI\ErrorPage.aspx"/>

In my ErrorPage.aspx.vb file

lblErrorDetails.Text = Session("CurrentError")

Now I am pretty sure that my problem has to do with context for the session,
but for the love of me I cannot figure out how to fix it. Also it seems that
the error message i am getting when i debug the Application_error routine is
a generic error message and not the system.exception message i am expecting
(example - I get the message (an unhandled exception has occured) instead of
the message (Login failed for PMAUser) when i debug the value
ex.Message.ToString in my DAL code. Why is this happening?

If anyone knows of where I can find an example of how to do what I am doing
or if you know how I can fix my Session problem I would much appreciate it.

Corey
Jul 21 '05 #1
3 1522
Corey,

I've run into this issue before, Session appears to not be available when an
exception occurs, so using it to save the exception is not an option, you can
save the exception in the Application or the Cache objects and you can even
use the SessionID as a key.

For the second problem you mention, the ASP.NET runtime wraps all exceptions
that from ASPX pages inside an HttpUnhandledException, so if you want the
original exception all you need to use is the "InnerException" property.

HTH!
Jorge

"CoreyMas" wrote:
This is what i am trying to do

I have a DAL that contains all of my database connections/reads etc.

I have a separate GUI layer that has my web pages

I would like to pass my exception errors in my DAL to a custom web page to
display to the user.

Here is what I have done so far

1. Created a CustomError web page that displays the error to the user in a
friendly format
2. Modified my Global.asax file to caputre the error and put it in a
Session variable.
3. Modified my Web.Config file to on error redirect my user to a custom
error page.

Problem - my error page comes up but there is no message being returned

Here is the code that I am using:

An example DAL code block throwing the exception

Public Function GetAllLevel1(ByVal ds As DataSet)

Dim myConnection As New
SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings("PMADataAccess"))
Dim myCommand As New SqlDataAdapter("sp_SelectAllLevel1",
myConnection)
Try
myCommand.Fill(ds, "AllLevel1")
Catch ex As Exception
Throw New System.Exception(ex.Message.ToString)
End Try
myConnection.Close()
Return ds
End Function

In Global.asax

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim LastError As Exception
LastError = Server.GetLastError()
Session("CurrentError") = LastError.Message
End Sub

In my Web.config file

<customErrors mode="On" defaultRedirect="GUI\ErrorPage.aspx"/>

In my ErrorPage.aspx.vb file

lblErrorDetails.Text = Session("CurrentError")

Now I am pretty sure that my problem has to do with context for the session,
but for the love of me I cannot figure out how to fix it. Also it seems that
the error message i am getting when i debug the Application_error routine is
a generic error message and not the system.exception message i am expecting
(example - I get the message (an unhandled exception has occured) instead of
the message (Login failed for PMAUser) when i debug the value
ex.Message.ToString in my DAL code. Why is this happening?

If anyone knows of where I can find an example of how to do what I am doing
or if you know how I can fix my Session problem I would much appreciate it.

Corey

Jul 21 '05 #2
Thank you Jorge,

Your idea about putting the error in Application state worked.

Corey

"Jorge Matos" wrote:
Corey,

I've run into this issue before, Session appears to not be available when an
exception occurs, so using it to save the exception is not an option, you can
save the exception in the Application or the Cache objects and you can even
use the SessionID as a key.

For the second problem you mention, the ASP.NET runtime wraps all exceptions
that from ASPX pages inside an HttpUnhandledException, so if you want the
original exception all you need to use is the "InnerException" property.

HTH!
Jorge

"CoreyMas" wrote:
This is what i am trying to do

I have a DAL that contains all of my database connections/reads etc.

I have a separate GUI layer that has my web pages

I would like to pass my exception errors in my DAL to a custom web page to
display to the user.

Here is what I have done so far

1. Created a CustomError web page that displays the error to the user in a
friendly format
2. Modified my Global.asax file to caputre the error and put it in a
Session variable.
3. Modified my Web.Config file to on error redirect my user to a custom
error page.

Problem - my error page comes up but there is no message being returned

Here is the code that I am using:

An example DAL code block throwing the exception

Public Function GetAllLevel1(ByVal ds As DataSet)

Dim myConnection As New
SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings("PMADataAccess"))
Dim myCommand As New SqlDataAdapter("sp_SelectAllLevel1",
myConnection)
Try
myCommand.Fill(ds, "AllLevel1")
Catch ex As Exception
Throw New System.Exception(ex.Message.ToString)
End Try
myConnection.Close()
Return ds
End Function

In Global.asax

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim LastError As Exception
LastError = Server.GetLastError()
Session("CurrentError") = LastError.Message
End Sub

In my Web.config file

<customErrors mode="On" defaultRedirect="GUI\ErrorPage.aspx"/>

In my ErrorPage.aspx.vb file

lblErrorDetails.Text = Session("CurrentError")

Now I am pretty sure that my problem has to do with context for the session,
but for the love of me I cannot figure out how to fix it. Also it seems that
the error message i am getting when i debug the Application_error routine is
a generic error message and not the system.exception message i am expecting
(example - I get the message (an unhandled exception has occured) instead of
the message (Login failed for PMAUser) when i debug the value
ex.Message.ToString in my DAL code. Why is this happening?

If anyone knows of where I can find an example of how to do what I am doing
or if you know how I can fix my Session problem I would much appreciate it.

Corey

Jul 21 '05 #3
Happy to be of service :)

"CoreyMas" wrote:
Thank you Jorge,

Your idea about putting the error in Application state worked.

Corey

"Jorge Matos" wrote:
Corey,

I've run into this issue before, Session appears to not be available when an
exception occurs, so using it to save the exception is not an option, you can
save the exception in the Application or the Cache objects and you can even
use the SessionID as a key.

For the second problem you mention, the ASP.NET runtime wraps all exceptions
that from ASPX pages inside an HttpUnhandledException, so if you want the
original exception all you need to use is the "InnerException" property.

HTH!
Jorge

"CoreyMas" wrote:
This is what i am trying to do

I have a DAL that contains all of my database connections/reads etc.

I have a separate GUI layer that has my web pages

I would like to pass my exception errors in my DAL to a custom web page to
display to the user.

Here is what I have done so far

1. Created a CustomError web page that displays the error to the user in a
friendly format
2. Modified my Global.asax file to caputre the error and put it in a
Session variable.
3. Modified my Web.Config file to on error redirect my user to a custom
error page.

Problem - my error page comes up but there is no message being returned

Here is the code that I am using:

An example DAL code block throwing the exception

Public Function GetAllLevel1(ByVal ds As DataSet)

Dim myConnection As New
SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings("PMADataAccess"))
Dim myCommand As New SqlDataAdapter("sp_SelectAllLevel1",
myConnection)
Try
myCommand.Fill(ds, "AllLevel1")
Catch ex As Exception
Throw New System.Exception(ex.Message.ToString)
End Try
myConnection.Close()
Return ds
End Function

In Global.asax

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim LastError As Exception
LastError = Server.GetLastError()
Session("CurrentError") = LastError.Message
End Sub

In my Web.config file

<customErrors mode="On" defaultRedirect="GUI\ErrorPage.aspx"/>

In my ErrorPage.aspx.vb file

lblErrorDetails.Text = Session("CurrentError")

Now I am pretty sure that my problem has to do with context for the session,
but for the love of me I cannot figure out how to fix it. Also it seems that
the error message i am getting when i debug the Application_error routine is
a generic error message and not the system.exception message i am expecting
(example - I get the message (an unhandled exception has occured) instead of
the message (Login failed for PMAUser) when i debug the value
ex.Message.ToString in my DAL code. Why is this happening?

If anyone knows of where I can find an example of how to do what I am doing
or if you know how I can fix my Session problem I would much appreciate it.

Corey

Jul 21 '05 #4

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

Similar topics

3
by: Steve | last post by:
All -- This occasionally happens, and there's no set pattern on why this is... perhaps it happens a few times every few months or so. I have a custom ATL COM object that handles data from...
14
by: sinister | last post by:
I have some CGI programs that spit out error pages when the user enters illegal form input. These custom error pages, while informing the user of errors, are otherwise just standard web pages. ...
9
by: Nick | last post by:
the customError feature is not working. I have it setup as the help says in my web.config file. <customErrors defaultRedirect="DsAppError.aspx" mode="RemoteOnly"/> I tried in a couple...
2
by: Matt | last post by:
Hello all, The app we are working on uses custom errors extensively to provide friendly error pages to users whilst logging the actual exceptions behind the scenes. However.... We are now...
0
by: Rhys666 | last post by:
OK, an issue I've come across before, but never found a cause for or resolution of, has decided to become the bane of my life again with ASP.Net Custom Error Pages. Basically, my web application...
3
by: CoreyMas | last post by:
This is what i am trying to do I have a DAL that contains all of my database connections/reads etc. I have a separate GUI layer that has my web pages I would like to pass my exception errors...
0
by: Pavan | last post by:
My name is Pavan and I am a software engineer working on ASP .Net web development. Currently I am using .Net 2.0 Professional Edition to develop my web pages. I have a problem
8
by: bryan | last post by:
I've got a custom HttpHandler to process all requests for a given extension. It gets invoked OK, but if I try to do a Server.Transfer I get an HttpException. A Response.Redirect works, but I really...
8
by: Mark A. Sam | last post by:
Hello I am working locally with Visual Web Developer 2005 Express. Before I even installed it, the information from Microsoft was that you could FTP it to a remote site and it should work. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.