How to get reference to Server object?

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

Kevin Spencer

System.Web.HttpContext.Current.Server

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
K

Karl

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
 
S

Scott Allen

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

Joe Rattz

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

Joe Rattz

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

Joe Rattz

Thanks for responding. This isn't quite what I was looking for. A couple
of other folks told me what I needed to know.
 
K

Karl

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
 
J

Joe Rattz

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.
 

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,780
Messages
2,569,611
Members
45,269
Latest member
vinaykumar_nevatia23

Latest Threads

Top