Link to home
Start Free TrialLog in
Avatar of bduhaish
bduhaishFlag for Saudi Arabia

asked on

<customErrors defaultRedirect="DefaultError.htm" mode="On" />

hi

in the web.config


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

------------you now the rest------------------


in ErrorPage.aspx  i displayed a frindly label like   label1.text = "Errors"

is there a way to now at lest the error code or the number code or a simple discription about the error

any examples in vb.net will be good
thanks.......................
Avatar of sachiek
sachiek
Flag of Singapore image


Exception ex = application.Server.GetLastError();

This will give you last error.

Then you can now use ex.Message or ex.ToString() to get relevent info of particular errror.


Sachi
I guess if you read this article in detail you will get more details

http://www.developer.com/net/asp/article.php/961301

The GetLastError() method of the Server object simply returns a reference to a generic HttpException. This is a wrapper that was placed around the original exception when it was passed from your ASP.NET page to the Application_Error event. To get access to the original exception, you need to call its GetBaseException() method. This will yield the original exception information, regardless of how many layers have been added to the exception tree.

Avatar of bduhaish

ASKER

about the first comment were should i type it

You can put in Page_Load of that errorPage.aspx


Sachi
Sorry but your answer is not clear and about the example in the above link I triad but I get a message say's operator '&' is not defined.


here is the example in the global.asax file

Imports System.Diagnostics

Sub Application_Error(sender As Object, e As EventArgs)
   'get reference to the source of the exception chain
   Dim ex As Exception = Server.GetLastError().GetBaseException()

   'log the details of the exception and page state to the
   'Windows 2000 Event Log
   EventLog.WriteEntry("Test Web", _
     "MESSAGE: " & ex.Message & _
     "\nSOURCE: " & ex.Source & _
     "\nFORM: " & Request.Form.ToString() & _
     "\nQUERYSTRING: " & Request.QueryString.ToString() & _
     "\nTARGETSITE: " & ex.TargetSite & _
     "\nSTACKTRACE: " & ex.StackTrace, _
     EventLogEntryType.Error)

   'Insert optional email notification here...
End Sub
In that case you try to put into one single line


EventLog.WriteEntry("Test Web", "MESSAGE: " & ex.Message & "\n SOURCE: " & ex.Source & "\nFORM: " & quest.Form.ToString() & "\nQUERYSTRING: " & Request.QueryString.ToString() & "\nTARGETSITE: " & ex.TargetSite & 
     "\nSTACKTRACE: " & ex.StackTrace, EventLogEntryType.Error)

"&" is to concat all those value and put into one string.



still the same but now  it's  highlighted on                    quest.Form.ToString()
sorry  Rquest.Form.ToString()
huh sorry - It should be -> >>>  Request.Form.ToString()

Can you just put this line instead of that line


EventLog.WriteEntry("Test Web", _
     "MESSAGE: " & ex.Message & _
     "\nSOURCE: " & ex.Source & _
     "\nTARGETSITE: " & ex.TargetSite & _
     "\nSTACKTRACE: " & ex.StackTrace, _
     EventLogEntryType.Error)
I don't get it the namespace is defined but still receiving the same error


c:\inetpub\wwwroot\WebApplication11\Global.asax.vb(52): Operator '&' is not defined for types 'String' and 'System.Reflection.MethodBase'.


sachiek  what do decide ???
Can you update me what are namespace you got in your Global.asax.vb?



Sachi
Imports System.Web
Imports System.Web.SessionState
Imports System.Diagnostics
Add below line

Imports System

still       ????????????????

I think there is now way, I couldn't finished the steps of this article because this error.



Pls Can you explain what you are trying to do?
I am quiet missing again what you are trying to do?

Please read this article.

Rich Custom Error Handling with ASP.NET
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/customerrors.asp

I hope you get it right this time,.


Sachi
Hi bduhaish ,
  There is still more good soultion and simple one avilabe.

  http://blogs.msdn.com/mattwag/archive/2005/02/07/368605.aspx
   Manually redirect to custom error  page.


Sachi  
 

 
ASKER CERTIFIED SOLUTION
Avatar of sachiek
sachiek
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry for been late ,i was out side the country and the last Comment  is clear .

thanks sachiek
No probelm.


Sachi