How Can I locate a namespace reference in asp.net?

  • Thread starter Thread starter mark4asp
  • Start date Start date
M

mark4asp

What is the best way to locate the namespace I need to put in a using
statement?

For example suppose I wanted to discover which namespace "Server" was
in the context of:

Exception ex = Server.GetLastError();

- code that is normally placed in Global Application_Error() but which
I want to put in a separate class.

How do I go about finding which particular namespace has a Server
class which includes a GetLastError method?
 
Keep in mind, when you're not coding in a web page or a user or web control
you need to use the full object path to get to things like the Server object
as such: HttpContext.Current.Server
 
Keep in mind, when you're not coding in a web page or a user or web control
you need to use the full object path to get to things like the Server object
as such: HttpContext.Current.Server

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006










- Show quoted text -

Thanks Mark, I had problems finding the "HttpContext.Current.Server"
bit.

I figured it out - all incredibly simple once you realise that Google
is not your friend but your enemy. Visual Studio is your friend.

1) In Visual Studio I put the line:
Exception ex = Server.GetLastError();
some place where it works (i.e. where a specific reference to the
namespace is not required) and where a breakpoint can reasonably be
set [Global Application_Error() won't do but
FormsAuthentication_OnAuthenticate() is fine as that's in Global too]
2) add a breakpoint there.
3) start debugging
4) add a watch for the desired object (Server) which tells me:

+ Server {System.Web.HttpServerUtility} System.Web.HttpServerUtility

Voila - the required namespace is "System.Web.HttpServerUtility"

So in I can now call my custom class in Global Application_Error():

string sError = CustomError.getError(Context, Request, Server, ref
sMessage);

and the header for my class method in CustomError is:

public static string getError(HttpContext Context, HttpRequest
Request, HttpServerUtility Server, ref string eMessage)

with no particular new using statements being needed in CustomError.

I feel the need to tell myself this even if everyone else already
knows it because it helps me remember things when I write them down.
 

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

Back
Top