473,396 Members | 1,884 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,396 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 1527
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...

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.