473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to get reference to Server object?

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.
Nov 18 '05 #1
8 4738
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
"Joe Rattz" <jo******@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
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.

Nov 18 '05 #2
System.Web.HttpContext.Current.Server

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

"Joe Rattz" <jo******@yahoo.com> wrote in message
news:#0**************@TK2MSFTNGP12.phx.gbl...
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.

Nov 18 '05 #3
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.

--
Scott
http://www.OdeToCode.com

On Fri, 20 Aug 2004 10:12:50 -0400, "Joe Rattz" <jo******@yahoo.com>
wrote:
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.


Nov 18 '05 #4
Thanks, this is what I needed.
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:9d********************************@4ax.com...
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.

--
Scott
http://www.OdeToCode.com

On Fri, 20 Aug 2004 10:12:50 -0400, "Joe Rattz" <jo******@yahoo.com>
wrote:
I am needing to get a reference to the HttpServerUtility obect (Server) froma method that does not have access to it. How should I do this?

Thanks.

Nov 18 '05 #5
Thanks, this is what I needed.
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:uA**************@TK2MSFTNGP09.phx.gbl...
System.Web.HttpContext.Current.Server

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

"Joe Rattz" <jo******@yahoo.com> wrote in message
news:#0**************@TK2MSFTNGP12.phx.gbl...
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.


Nov 18 '05 #6
Thanks for responding. This isn't quite what I was looking for. A couple
of other folks told me what I needed to know.

"Karl" <none> wrote in message news:OR**************@TK2MSFTNGP10.phx.gbl...
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
"Joe Rattz" <jo******@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
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.


Nov 18 '05 #7
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

"Joe Rattz" <jo******@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Thanks for responding. This isn't quite what I was looking for. A couple
of other folks told me what I needed to know.

"Karl" <none> wrote in message

news:OR**************@TK2MSFTNGP10.phx.gbl...
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
"Joe Rattz" <jo******@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
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.



Nov 18 '05 #8
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.
"Karl" <none> wrote in message
news:u8***************@tk2msftngp13.phx.gbl...
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

"Joe Rattz" <jo******@yahoo.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Thanks for responding. This isn't quite what I was looking for. A couple
of other folks told me what I needed to know.

"Karl" <none> wrote in message

news:OR**************@TK2MSFTNGP10.phx.gbl... 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
"Joe Rattz" <jo******@yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
> 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.
>
>



Nov 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Moe Sizlak | last post by:
Hi There, I am trying to write the selected value of a listcontrol when a button is clicked and I keep getting the error "object not set to a reference of an object". The libox itself is in a...
6
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result page...
1
by: Mike Clark | last post by:
I have a webservice that works great on localhost, but as soon as I promote to a network server I get an exception that doesn't tell me much. There's some implementation details in this exception...
5
by: Mike Logan | last post by:
I used WSDL.exe to generate a client side web proxy for a web service, called the web service, got the results but an array returned by the web service is not in the results. However if I use...
0
by: Richard Gregory | last post by:
Hi, I have the wsdl below, for an Axis web service, and when I select Add Web Refernce in Visual Studio the proxy is missing a class representing the returnedElementsType (see reference.cs below...
8
by: Charlie J | last post by:
I have a real stumper. I added a server side table to a home page that has two other server side tables on it that have been working great. In Visual Studio everything works great. When I put...
2
by: danielle.m.manning | last post by:
I have a question about a problem I am having with attempting to port some old ASP code to ASP.NET. We have a dll out there which we downloaded which creates GUIDs for session management. In...
3
by: SAL | last post by:
I am getting the following ERROR in my WebApp on line 30: Server Error in '/TestWebApp' Application. -------------------------------------------------------------------------------- Object...
1
by: Mike H | last post by:
I can't seem to figure out the right thing to search on, so I thought I'd just provide an example and see if someone can point me to some tips. What I have is an Automation Server that has a...
0
markrawlingson
by: markrawlingson | last post by:
Hello, So I've got a list of functions written in ASP Classic which I include into every page within my application(s). This file is getting quite big and in most scenarios needs to be called 4-5...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.