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 | | | | re: Custom error web pages problem
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:
[color=blue]
> 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[/color] | | | | re: Custom error web pages problem
Thank you Jorge,
Your idea about putting the error in Application state worked.
Corey
"Jorge Matos" wrote:
[color=blue]
> 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:
>[color=green]
> > 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[/color][/color] | | | | re: Custom error web pages problem
Happy to be of service :)
"CoreyMas" wrote:
[color=blue]
> Thank you Jorge,
>
> Your idea about putting the error in Application state worked.
>
> Corey
>
> "Jorge Matos" wrote:
>[color=green]
> > 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:
> >[color=darkred]
> > > 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[/color][/color][/color] |  | Similar .NET Framework bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|