Hi

I am creating some error trapping code that will email me when a error occurs in asp code. Alot of

the code works, except perhaps one of the most vital pieces of information line number of the error

I have tried

ASPError.Line

&

set objErr=Server.GetLastError()
objErr.Line

&

Err.Line

I get nothing returned or the object im looking at, or it is errorous. Im using IIS 6. Does anyone

have any ideas of how to get the line number of an error? You would think it would be a important

thing to be able to return and simple too.

Thanks in advance for any help
Rob

Dani AI

Generated

Short answer: you can get a line number from Classic ASP, but only from the ASPError object returned to a custom 500;100 error page — not from Err.Line on ordinary pages. The Server.GetLastError API returns an ASPError object (including File and Line), and it is only meaningful when IIS transfers control to your custom 500;100 handler before any ASP content is emitted. (learn.microsoft.com)

The usual reason Line comes back blank is IIS configuration. The custom ASP error handler must be configured so IIS executes the URL (Server.Transfer-style) for the 500;100 substatus rather than redirecting or serving a static file; that preserves request state and the ASPError data. Put the handler inside the same application (same app pool) and call Server.GetLastError as the very first thing in that handler, then log/email File, Line, Description, etc. Also remember IIS by default gives detailed errors only to local requests — remote clients will see generic/custom pages unless you change error mode for debugging. (learn.microsoft.com)

Troubleshooting checklist:

  • Ensure you have a 500;100 custom error mapped to an ASP page inside the same site/application and that the mapping uses Execute URL / "URL" (not Redirect/File). (ftp.zx.net.nz)
  • Make sure the error handler emits no output before calling Server.GetLastError (it must run before the page sends content). (learn.microsoft.com)
  • If the error comes from a compiled component (DLL) you may not get a useful script line.
  • On shared hosting you may not be able to change the custom-error mapping; fall back to per-page On Error Resume Next + structured logging if needed.

was correct to point you at the 500-100 approach; and saw blanks because the IIS handler/context wasn’t preserved (or output was already sent). For authoritative reference on Server.GetLastError and custom ASP error pages see Microsoft’s Server.GetLastError documentation and the IIS custom/errors docs. (learn.microsoft.com)

Recommended Answers

All 2 Replies

I have tried the same exact thing. I was never able to get the line number to come up.

The syntax for returning the line number of the ASP error using the GetLastError object is :

set objError = Server.GetLastError()
strErrorLine =  objError.Line

Note though that you cannot use this in your standard asp application pages and expect it to work. You need to modify the default error page (500-100.asp) which handles ASP error reporting and displays the results on the screen. To get the error emailed to you you can replace this page with your own version which will display a custom message to the user and then email the error report to you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.