Showing posts with label logging. Show all posts
Showing posts with label logging. Show all posts

Saturday, March 24, 2012

Server Variables

Hi - i'm trying to get my application to detect the user id the user is logging onto my application with.
In classic ASP it was easy
Request.ServerVariables("AUTH_USER")

but it just wont work for me in .net
I've tried...

Request.ServerVariables("AUTH_USER")

and

Request.ServerVariables.Item("AUTH_USER")

Neither of them work i get what appears to be a permissions problem
The error i get is "Request is not available in this context"
Then it says it cant show me teh source unless i set debug="true" - but i have in both page and web.config so i don't know what's going on there either!

Anyone?

CheersThe error is about the Request object itself. The rest of that statement doesn't matter until you can get access to Request. Request is available on any method within a Page or UserControl class. If your code is in another object, you can reference it with HttpContext.Current.Request.

Thursday, March 22, 2012

Server.GetLastError()

I am using Server.GetLastError() to get error details for logging, which is fine, but what I really need is the actual line of code that caused the error.

If you don't have a custom error page, it shows you the actual line that caused the error but I can't seem to find it in the Server.GetLastError() object.

I have noticed that the following code gets me the name of the procedure in which the error occurred:
appException = Server.GetLastError()
MsgBox(appException.TargetSite.Name)

But not the actual line of code that triggered the error.Look at the properties of the exception named SOURCE, MESSAGE, STACKTRACE.
I have. They don't give me what I need.
Sorry, I haven't been able to find anything for this. It seems like the line-of-code that's erroring out is something that the framework keeps to itself, for security purposes? :confused:
Oh dear...:(
One thing to make sure of:

Did you compile the Application to DEBUG and no RELEASE? Lines of code are not available in release compiles. Also, make sure that the PDB file got uploaded. This is the debug trace hook file.

All that said, it is entirely possible it will not keep the line number around because you have to execute this code (Server.GetLastError()) AFTER the page exception occurs and is thrown, which has probably cleared the exception stack already.