How to get reference to Server object?

  • Thread starter Thread starter Joe Rattz
  • Start date Start date
J

Joe Rattz

I am needing to get a reference to the HttpServerUtility obect (Server) from
a method that does not have access to it. How should I do this?

Thanks.
 
System.Web.HttpContext.Current.Server

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Two options:
First check out System.Web.HttpUtility it has a number of static methods
that you can use...though it isn't the full list available from an instance
of the HttpServerUtility class.

If you need something from HttpServerUtility, check:
System.Web.HttpContext.Current.Server which is a reference to the same
Server instance you have in pages. HttpContext.Current could return a null
value if your code isn't inside a web-request, so you might wanna check for
null and gracefully handle the exception...or not...

Karl
 
Hi Joe:

You can get there with the current property of the HttpContent class:
HttpContext.Current.Server. Make sure to include the System.Web
namespace.
 
Thanks, this is what I needed.
Kevin Spencer said:
System.Web.HttpContext.Current.Server

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Thanks, this is what I needed.
Scott Allen said:
Hi Joe:

You can get there with the current property of the HttpContent class:
HttpContext.Current.Server. Make sure to include the System.Web
namespace.
 
Thanks for responding. This isn't quite what I was looking for. A couple
of other folks told me what I needed to know.
 
I told you the same thing as everyone else :P my 2nd option was the same as
all others....my answer was the best..the BEST! :P

it's cool :)

karl
 
You are correct, sir!. My poor reading prevented me from reading the full
message. I had already obtained the answer I wanted from the post just
prior to yours and when I saw the depth of knowledge in your answer, I must
have swooned and become dizzy because I did not see that you too had
everything theirs did plus some.

Good times.
 
Back
Top