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

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?
 
M

Mark Fitzpatrick

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
 
M

mark4asp

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.
 
R

Riki

Juan T. Llibre said:
re:
!> What is the best way to locate the namespace I need to put in a using
statement?

Look it up in the .Net Framework Class Browser :

http://quickstarts.asp.net/QuickStartv20/util/classbrowser.aspx

You may also want to use the F1 button in Visual Web Developer or Visual
Studio.
Put the cursor on the word "Server" in your code, and press F1.

Usually, it will bring you straight to the right page with all the
information.

Riki
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top