server.mappath

C

Colin

In the code behind server.mappath works fine, yet in a class I get 'Server
operation is not available in this context'. System.Web.HttpApplication is
inherited in the class, why is this so?

Colin.
 
S

S. Justin Gengo

Colin,

It's not enough to just inherit it. The page fills many properties of the
class. If you pass the current instance of the HttpApplication object into
your class then you'll be able to access it the way you want.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
C

Colin

Ah, I see. Classes are new'ish to me. How did I pass HttpApplication to
the class when instantiated? I'm using Vb.Net.

Colin.


message Colin,

It's not enough to just inherit it. The page fills many properties of the
class. If you pass the current instance of the HttpApplication object into
your class then you'll be able to access it the way you want.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
E

Edwin Knoppert

Inside a class you could use:
System.Web.HttpContext.Current.Server.MapPath("~/mydir/")
 
S

S. Justin Gengo

Colin,

If you always want it to be included then require it as a parameter of your
class' sub new:

Private _HttpApplication

Public Sub New(ByRef httpApplication As System.Web.HttpApplication)
_HttpApplication = httpApplication
End Sub

If you just need it for one method inside of your class declare it as a
parameter of that method itself

Public Sub MyMethod(ByRef httpApplication As System.Web.HttpApplication)

End Sub

You should use ByRef instead of ByVal so that if you store something in the
HttpApplication.Context object or make other changes to it's properties they
will be reflected throughout the application.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

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

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,098
Latest member
KetoBaseReview
Top