Where's this "server" object?!

G

Guest

Hi peeps

I'm just following this HOW-TO from MSDN..
http://support.microsoft.com/default.aspx?scid=kb;en-us;306355

But I've got a problem. I've adding the #using System.Diagnostics; line to
my cs file, but when I try and type the following line...

Exception objErr = Server.GetLastError().GetBaseException();

the IDE isn't picking up on the Server. - it's not giving me any
intellisense, which makes me assume it doesn't understand.

What do I need to be #using to get the Server object?!

Cheers


Dan
 
G

Guest

Hello Mate,

Server is under System.Web.HttpServerUtility, so including System.Web.

HTH,

Jon
 
G

Guest

Or not... :)

I've included System.Web and it's still not giving me anything. Is this
something to do with the fact that I'm trying to use this from my own class
rather than a Page?!

Don't understand... here's the code...

using System;
using System.Diagnostics;
using System.Web;
using System.Web.UI;

namespace DansSpace
{
public class CrashRecovery
{
...

private void StoreBug()
{
Exception excp = Server. (wont give me anything...)
}
}
}

What am I doing wrong!?!

Cheers


Dan
 
S

Steven Spits

dhnriverside said:
I've included System.Web and it's still not giving me anything. Is this
something to do with the fact that I'm trying to use this from my own
class
rather than a Page?!

Yes, Server is a property of the page object. If your class doesn't inherit
from Page, include the following line:

System.Web.HttpServerUtility Server = HttpContext.Current.Server;

Steven

- - -
 
G

Guest

Okay, done that, it compiles but crashes with an "object reference not set to
an object" error..

System.Web.HttpServerUtility Server = HttpContext.Current.Server;
Exception ex = Server.GetLastError().GetBaseException(); // this line fails

What's am I missing here?! I'm trying to Google for info, but I'm not
finding anything about why this is happening, or how to achieve this.

Thanks all for your continuing help...
 
S

Steven Spits

dhnriverside said:
Okay, done that, it compiles but crashes with an "object reference not set
to
an object" error..

System.Web.HttpServerUtility Server = HttpContext.Current.Server;
Exception ex = Server.GetLastError().GetBaseException(); // this line
fails

Is Server null or does GetLastError() return null? My guess is the latter.

If GetLastError() return null, it means there isn't an error or it was
already reset. Try calling this method earlier and pass the exception as a
parameter.

Without more code, this is the best advice I can give you.

Steven

- - -
 
A

Alan Silver

Okay, done that, it compiles but crashes with an "object reference not
set to an object" error..

System.Web.HttpServerUtility Server = HttpContext.Current.Server;
Exception ex = Server.GetLastError().GetBaseException(); // this line
fails

Note Steve's words "If your class doesn't inherit from Page"

Have you tried inheriting from Page? That's what I tend to do and it
gives access to such things as Server.

public class CrashRecovery : Page {

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,607
Members
45,240
Latest member
pashute

Latest Threads

Top