473,404 Members | 2,170 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,404 software developers and data experts.

server.mappath

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.
Nov 19 '05 #1
4 2867
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
"Colin" <c@..cl> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
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.

Nov 19 '05 #2
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.
"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:eh**************@tk2msftngp13.phx.gbl...
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
"Colin" <c@..cl> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
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.


Nov 19 '05 #3
Inside a class you could use:
System.Web.HttpContext.Current.Server.MapPath("~/mydir/")
"Colin" <c@..cl> schreef in bericht
news:u2**************@TK2MSFTNGP10.phx.gbl...
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.

Nov 19 '05 #4
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
"Colin" <c@..cl> wrote in message
news:OE*************@TK2MSFTNGP10.phx.gbl...
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.
"S. Justin Gengo" <justin@[no_spam_please]aboutfortunate.com> wrote in
message news:eh**************@tk2msftngp13.phx.gbl...
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
"Colin" <c@..cl> wrote in message
news:u2**************@TK2MSFTNGP10.phx.gbl...
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.


Nov 19 '05 #5

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

Similar topics

13
by: John Rebbeck | last post by:
I've got the directory f:\Company\Product set as web shared so it's got a virtual directory in the default web site on my test server's IIS. If I try to use Server.MapPath in that site it returns a...
4
by: Laphan | last post by:
Hi All Sorry to be irate, but the whole concept of Server.MapPaths really has me in a tiswas!! In order to confirm once and for all, could you please advise me on the following: 1) There...
6
by: darrel | last post by:
I have some functions that are reading/writing to the file system. As such, they use server.mapPath a lot to navigate it all. Since I'm using these functions numerous times throughout my...
7
by: benoit | last post by:
Hi, if I write this code to retrieve a folder on the server Server.mappath("/DATA") I get this error message System.InvalidOperationException: Failed to map the path '/DATA' the virtual...
14
by: Lorenzo | last post by:
Hello, I have a web application with a virtual directory in it. With 'virtual directory' i mean a folder whose physical path is different from the physical path of the application, but in which...
5
by: MichiMichi | last post by:
When using Server.MapPath on IIS 5 on my localhost everything works well. All of the following commands are executed without any error Response.Write(Server.MapPath("/app_test") & "<br>")...
4
by: vunet.us | last post by:
How to use server.mappath() parent folder correctly: Server.MapPath("../test.asp") Thank you for the hint.
3
by: rn5a | last post by:
Server.MapPath returns the physical file path that corresponds to the specified virtual path whereas Request.MapPath maps the specified virtual path to a physical path. Assuming that a file named...
6
by: withers | last post by:
If I run Server.MapPath("/") on my operational Internet server I get, correctly, the physical path to the directory my page is in (d:\.... \...\htdocs). If I run Server.MapPath("/") on my...
3
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have one line code in my program, occasionaly I will receive the following error: "The Path parameter for the MapPath method did not correspond to a known path" ...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.