Accessing Server.Mappath from SoapExtension

P

PA

I need to log all incoming soap messages in a file.

I have follwing code in WriteInput routine of SoapExtension class

Dim Server As System.Web.HttpServerUtility

AppPath = Server.MapPath("App.ini")

When I run the application, I get following error:

Object reference not set to an instance of an object to server.MapPath line.

can anyone tell me how to access/Set Server and it's properties?

Or is there any other way to access a particular file?

Thanks in advance.

Pratibha
 
D

Dino Chiesa [Microsoft]

you have not initialized your Server variable.

you want

Dim Server As System.Web.HttpServerUtility
Server = System.Web.HttpContext.Current.Server

A defensive coder may want to do this:

if (System.Web.HttpContext.Current <> nothing ) then
Server = System.Web.HttpContext.Current.Server
...


(sorry I don't know VB syntax but you get the idea...)

In other words, the System.Web.HttpContext.Current is a static member. If
it is not set, then you have no HttpContext (which means your code is
probably not running within ASP.NET) and if you have no context, then you
cannot access the Server property of that context.

-Dino
 

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,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top