On 27 Apr, 13:01, "Mark Fitzpatrick" <markf...@fitzme.comwrote:
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
"mark4asp" <mark4...@gmail.comwrote in message
news:11**********************@r3g2000prh.googlegro ups.com...
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?- Hide quoted text -
- 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.